Home  >  Article  >  Backend Development  >  Implementation code for sending emails with PHPMailer_PHP tutorial

Implementation code for sending emails with PHPMailer_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:10:45783browse

Native environment: LAMP (ubuntu12.10);

The SMTP server uses stmp.163.com. I was still worried about this at first. I first used stmp.qq.com, but all the emails I sent were treated as spam by Tencent and could not be sent out.

Why haven’t I passed this content? Then I changed it to stmp.gmail.com, and then opened the POP service of Google Mail, but the verification could not be successful. Finally, register a 163 and run the code successfully.

No pain, no pressure~~

The code is as follows:

Copy the codeThe code is as follows:

require("PHPMailer/class.phpmailer.php");
require("PHPMailer/class.smtp.php");

$mail=new PHPMailer();

// Set PHPMailer to use SMTP server to send Email
$mail->IsSMTP();

// Set the character encoding of the email, if not specified, it will be 'UTF-8'
$ mail->CharSet='UTF-8';

// Add recipient address, which can be used multiple times to add multiple recipients
$mail->AddAddress('** *******@qq.com');

// Set the email body
$message='This is a test email';
$mail->Body=$message;
// Set the From field of the email header.
// For NetEase's SMTP service, this part must be the same as your actual account, otherwise verification errors will occur.
$mail->From='****@163.com';

// Set the sender name
$mail->FromName='yourname';

// Set the email title
$mail->Subject='Email Test';

// Set up the SMTP server. NetEase's SMTP server is used here.
$mail->Host='smtp.163.com';

// Set to "Require verification"
$mail->SMTPAuth=true;

//Set the username and password, that is, the username and password of NetEase Mail.
$mail->Username='****';
$mail->Password='****';

// Send email.
$mail->Send();
?>

The second and third lines contain the PHP email sending package. The download addresses written by other blogs on the Internet are It's http://phpmailer.sourceforge.net/, but I haven't opened it, so I'd better write it here.

I downloaded it from Baidu. You can still find it on Baidu.

There is a mail() function in PHP for sending emails, but you need to install sendmail. I installed it but didn’t send it out. I don’t know if there is something wrong with the configuration or some other reason. In short, this ended up being like this Simple method achieved.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327042.htmlTechArticleLocal environment: LAMP (ubuntu12.10); the SMTP server uses stmp.163.com. I was still worried about this at first. I first used stmp.qq.com, but all the emails I sent were treated as spam by Tencent...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn