This article mainly share with you the method that PHP uses phpmailer send mail, hope can help everybody.
Environment: php5.6
Need to import message class package
Preparatory work:
Log in to send the email account, open the Settings center, turn on the SMTP service, set the authorization code
Open Tutorial: https://jingyan.baidu.com/article/fdbd42771da9b0b89e3f48a8.html
When sending a message, the user name is the mailbox account, the password is the authorization code set
//recipient address $address = ' 14321916@qq.com ';//title $subject = ' Test message ';//information $message = ' Content Content Content content content contents '; function Sp_send_email ($address, $subject, $message) {$mail =new \phpmailer ();//Set Phpmailer send with SMTP server email$mail- >ISSMTP (); $mail->ishtml (TRUE);//Set the character encoding of the message, if not specified, ' UTF-8 ' $mail->charset= ' UTF-8 ';//Add the recipient address, You can use it multiple times to add multiple recipients $mail->addaddress ($address);//Set the message body $mail->body= $message;//Set the From field of the message header. $mail->from= ' 15998186418@163.com ';//Set the sender's name $mail->fromname= ' you guess who I am ';//Set the message header $mail->subject= $subject; /Set up an SMTP server. $mail->host= ' smtp.163.com ';//Set the SMTP server port. $mail->port= "25";//Set to "Require authentication" $mail->smtpauth=true;//set user name and password. $mail->username= ' 123456@163.com '; $mail->password= ' 123456 ';//Send mail. $res = $mail->send (); return $res;//Successful return true}