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