PHP sends mail with Phpmailer

Source: Internet
Author: User

Send mail

1. To ensure security, the URL that is sent to the message needs to be generated, the main parameters (key (key needs to automatically generate random code each time)) and then send the URL to the mailbox.

2. Resolve the URL: first, according to the user name from the database to find the key key and expiration time, no means that the request is forged or expired, and then verify the signature, verify the expiration time, both verify through, you can modify the password, after the password modification, delete the database records.

Note: But I did not use the database, but used Redis. Only one unique code is used on the link, the GUID of the user is obtained from the unique code to Redis, and the connection fails after 3,600 seconds (Redis self-processing).

$client = Redis ();

$client->setex ($linkkey, 7200, $userInfo [' GUID ']);

To open port 25 on the server, the message cannot be sent.

 /**     *  Send mail Method      *       *  @param  string  $from   from      *  @param   string  $to   Recipient address      *  @param  string  $subject    Message title      *  @param  string  $body   message body       */    public function postmail ($from, $to, $subject  = , $body  =   ') {        error_reporting (E_all);         date_default_timezone_set (' Asia/shanghai ');//Set time zone East area eight          vendor (' Phpmailer.class#phpmailer ');         vendor (' Phpmailer.class#smtp ');         $mail             &Nbsp; = new \phpmailer ();       //new a PHPMailer object come out           $body              = eregi_replace ("[\]", ",", $body);  //filtering the contents of the message as necessary           $mail->charset = "UTF-8";                    //set the message encoding, the default iso-8859-1, if the Chinese this item must be set, otherwise garbled           $mail->issmtp ();                            //  setting up using the SMTP service          $mail->host       =   ' smtp.ym.163.com ';        // smtp  server//           $mail->smtpdebug  = 1;                      //  Enable SMTP Debugging  1 =  errors  2 =  messages         $mail smtpauth   = true;                   //  server needs verification          $mail port       = 25;          Port number of the            // SMTP server          265/255  25                  $mail->username   =  ' user name ';    //  SMTP Server user name          $mail->password   =  ' password ';            // SMTP Server password          $mail- >ishtml (True);         $mail->setfrom (' E-mail address ',  $from);          $mail->subject    =  $subject;          $mail->msghtml ($body);          $address  =  $to;         $mail->addaddress ($address,   ");        //           $mail->addembeddedimage ("public/bee/common/images/logo3.jpg",  "logoimg", "logo.jpg");  // Set the picture in the message//          $mail->addattachment ("public/bee/common/ Images/logo3.jpg "); // attachment  Accessories         if (! $mail->send ())  {             echo  ' mailer error:  '  . $ mail->errorinfo;        } else {             echo  "message sent! Congratulations, the Mail was sent successfully! ";         }    }


PHP sends mail with Phpmailer

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.