Phpmailer is a PHP function package that is used to send e-mail. The features it provides include:
*. Specify multiple recipients, CC addresses, dark addresses, and reply-to addresses when sending mail
*. Support for multiple message codes including: 8bit,base64,binary and Quoted-printable
*. Support SMTP Authentication
*. Support for redundant SMTP servers
*. Support for messages with attachments and HTML-formatted messages
*. Custom message headers
*. Support for embedding pictures in messages
*. Flexible Commissioning
*. tested and compatible SMTP servers include: Sendmail,qmail,postfix,imail,exchange, etc.
*. can be run on any platform
Mail Send instance
The code is as follows |
Copy Code |
<?php Require ("phpmailer/class.phpmailer.php"); Require ("phpmailer/class.smtp.php"); $mail =new Phpmailer (); Set up Phpmailer use SMTP server to send email $mail->issmtp (); Sets the character encoding for the message, if unspecified, the ' UTF-8 ' $mail->charset= ' UTF-8 '; Add a recipient address that can be used multiple times to add multiple recipients $mail->addaddress (' ********* @qq. com '); Set the message body $message = ' <B> This is a test email </B> '; $mail->body= $message; Sets the From field of the message header. For NetEase's SMTP service, this part must be the same as your actual account number, or it will verify an error. $mail->from= ' ****@163.com '; Set Sender Name $mail->fromname= ' yourname '; Set Message headers $mail->subject= ' mail test '; Set up an SMTP server. NetEase's SMTP server is used here. $mail->host= ' smtp.163.com '; Set to require verification $mail->smtpauth=true; Set user name and password, that is, NetEase Mail username and password. $mail->username= ' * * * * *; $mail->password= ' * * * * *; Send the message. $mail->send (); ?> |
Summary of some common problems in phpmailer email
Phpmailer Message classes Use error analysis
One, there is no definition send mailbox $mail->from or malformed, error prompt: Language string failed to load:recipients_failed Test@test.com, note that this configuration must be correct, and that the correct mailbox
Second, there is no definition of a mail service host $mail->host or connection failure, error message: Language string failed to Load:connect_host
Three, did not define send mailbox $mail->addaddress or mailbox format is incorrect, error prompt: Language string failed to load:provide_address
Four, did not define mailbox send username $mail->username, error hint: Language string failed to Load:connect_host
Five, does not define the mailbox sends the password $mail->password, the error prompt: Language string failed to Load:connect_host, this kind of error is very obvious, generally is the mailbox server configuration is not correct cannot edge to receive.
Six, the message body encoding, if sending an HTML message, needs to define the correct encoding format and character, send the GBK message as follows:
code is as follows |
copy code |
$mail-> IsHTML (TRUE); Whether to support HTML mail $mail->charset = "GB2312"; character settings $mail->encoding = "base64"; encoding |