The Phpmailer configuration checklist is as follows:
- Require_once 'class.phpmailer.php';
- $receiver = ";
- $mail = new Phpmailer ();
- $mail-issmtp ();
- $mail-ishtml (true);
- $mail-CharSet = "Gb2312″;
- $mail-Encoding = "Base64″;
- $mail,Host = ' mail.test.com ';
- $mail,Port = 25;
- $mail-Smtpauth = true;
- $mail-Username = ' Test ';
- $mail-Password = ' Test ';
- $mail from = ' [email protected] ';
- $mail-FromName = ' [email protected] ';
- $mail-addaddress ($sendto _email, $receiver);
- $mail-Subject = ' phpmailer mail test ';
- $mailBody = ' phpmailer mail test ';
- if (! $mail,Send ()) {
- Echo $mail-errorinfo; exit ();
- }
- echo ' success ';
Phpmailer Message Class Usage Error analysis
One, does not define send mailbox $mail->from or malformed, error prompt: Language string failed to load:recipients_failed [email protected], note , this configuration must be correct, and is the correct mailbox
Two, there is no mail service host defined $mail->host or Connection failed, error message: Language string failed to Load:connect_host
Three, there is no definition to send the mailbox $mail->addaddress or the mailbox format is incorrect, error message: Language string failed to load:provide_address
Four, does not define the mailbox send user name $mail->username, error message: Language string failed to Load:connect_host
Five, no defined mailbox send password $mail->password, error message: Language string failed to load:connect_host, such errors are very obvious, The mailbox server is generally configured incorrectly and cannot be connected.
Six, message body encoding, if you send an HTML message, you need to define the correct encoding format and character, send GBK message as follows:
$mail->ishtml (TRUE); Whether HTML mail is supported
$mail->charset = "Gb2312″; Character settings
$mail->encoding = "Base64″; Encoding method
After configuration, you can send HTML messages directly, as follows:
-
-
- <meta http-equiv= "Content-type" content= "text/html; CharSet=gb2312"/>
- <title>phpmailer Mail Test </title>
-
- <body>
- <div>phpmailer Message Class Usage Error analysis </div>
- </body>
-
Seven, learn to use the error prompt correctly $mail->errorinfo View the message error, you can directly find the problem.
Using the Phpmailer message class to send messages using a very simple, basic configuration as shown above, in the use of the correct understanding of error prompts, and timely understanding of the cause of the error, for the correct use of Phpmailer message class is very important.