Implementation code for PHPMailer mail sending

  • 2020-06-01 08:59:26
  • OfStack

Local environment: LAMP (ubuntu12.10);

The SMTP server USES At the beginning, it was painful. The first one I used was As a result, all the emails I sent were treated as spam by tencent and could not be sent out.

I didn't say anything about it. Then I changed it to, and opened the POP service in the Google mailbox, but I couldn't verify it was successful. Finally, register 1 163 and run the code successfully.

No pain, no pressure

The code is as follows:


 $mail=new PHPMailer();

 //  Set up the PHPMailer use SMTP Server send Email

 //  Sets the character encoding of the message, if not specified 'UTF-8'

 //  Add recipient addresses, which can be used multiple times to add multiple recipients 

 //  Set the message body 
 $message='<B> This is a 1 Test email </B>';
 //  Set the message header From Field. 
 //  For netease SMTP Service, this part must be the same as your actual account, otherwise the validation will be wrong. 

 //  Set the sender name 

 //  Set the subject line 
 $mail->Subject=' Mail test ';

 //  Set up the SMTP The server. I'm using netease here SMTP The server. 

 //  Set to "need validation" 

 //  Set the username and password, that is, the username and password for the netease mail. 

 //  Send an email. 

Line 2 and line 3 is PHP mailing package contains, other blog online download address is this http: / / phpmailer sourceforge. net /, but I didn't open, or in the writing.

Mine is under baidu. Baidu 1 can still be found.

PHP has an mail() function for sending emails, but I need to install an sendmail. I installed it but didn't send it. I don't know if there is some configuration problem or some reason, but it was finally implemented in this simple way.

Related articles: