Phpmailer for automatic mail sending by PHP

Source: Internet
Author: User
Tags mail account

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-&GT;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-&GT;ADDCC (' [Email protected]‘);$mail-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.