Generally register a new account, will receive an official mail, then how to set up an automatic mail system for their own projects?
First, have their own e-mail account, the 163 mailbox as an example.
Second, open the client authorization code, only after the opening to the PHP code, control the automatic sending of mail.
In PHP, the password you need to use is to turn on the password that was set after the mailbox client was authorized.
Third, the download of Phpmailer
: Https://github.com/PHPMailer/PHPMailer
Relevant instructions for use on GitHub
The message sending code is as follows:
Require' Phpmailerautoload.php‘; Load the classes that need to be used, or use: Include ("class.phpmailer.php"); Include ("class.smtp.php");$mail=NewPhpmailer;$mail->smtpdebug = 3; Enable Verbose debug output$mail->ISSMTP ();Set Mailer to use SMTP$mail-Host=' Smtp1.example.com‘;Specify main and backup SMTP servers set up a mailbox server, depending on the type of their mailbox, such as 163 mailbox: $mail->host = "smtp.163.com";$mail-Smtpauth=TrueEnable SMTP Authentication$mail-Username=' [Email protected]‘;SMTP username your own e-mail account$mail-Password=' Secret‘;SMTP password your own account password$mail-Smtpsecure=' TLS‘;Enable TLS encryption, ' SSL ' also accepted Mailbox server uses a confidential protocol 163 mailbox to annotate this entry$mail-Port=587;TCP port to connect to 163 mailbox server ports: 25$mail->setfrom (' [Email protected]‘,' Mailer‘);$mail->addaddress (' [Email protected]‘,' Joe User‘);ADD a recipient can be set to send to multiple users$mail->addaddress (' [Email protected]‘);Name is optional$mail->addreplyto (' [Email protected]‘,' Information‘);$mail->ADDCC (' [Email protected]‘);$mail->ADDBCC (' [Email protected]‘);$mail->addattachment ('/var/tmp/file.tar.gz‘);Add attachments adding attachments, without attachments, comments can be$mail->addattachment ('/tmp/image.jpg‘,' New.jpg‘);Optional Name$mail->ishtml (true);Set Email format to HTML$mail-Subject=' Here is the subject‘; Subject of the message$mail-Body=' This is the HTML message body <b>in bold!</b>‘; Content of the message$mail-Altbody=' This was the body in plain text for non-html mail clients‘;If!$mail->send ()) { echo ' Message could not being Sent. '; echo ' Mailer Error: " $mail ->errorinfo;} else { echo "Message has been Sent "}
Four, the message garbled problem resolution:
A. Resolving non-heading Chinese characters garbled
in Phpmailer library file class.phpmailer.php,
Find public $CharSet = ' iso-88 59-1 ';
Change to public $CharSet = ' UTF-8 ';
and save the file in the UTF-8 format.
B. Fix title Chinese characters garbled
$mail->subject = "=?utf-8? B? ". Base64_encode ("Your headline content"). "? =";
/span>
PHP phpmailer automatic message sending