Home >Backend Development >PHP Tutorial >Use PHPMailer to share code for sending emails, send emails with phpmailer_PHP tutorial

Use PHPMailer to share code for sending emails, send emails with phpmailer_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:13820browse

Use PHPMailer to share code for sending emails, send emails with phpmailer

Sending emails is a commonly used function. LZ also encountered it in the project today, so I would like to share it.

First, download PHPMailer

1. https://github.com/dwqs/PHPMailer

2. http://download.csdn.net/detail/u011043843/8063583

After downloading, decompress the file to the corresponding location in the project directory, introduce class.phpmailer.php and class.smtp.php into the project, and look at the code: (Do not delete the decompressed file, otherwise it will not work)

<&#63;php <br />  // 必要导入<br /> require("class.phpmailer.php");<br /> require("class.smtp.php");<br /> date_default_timezone_set('Asia/Shanghai');//设定时区东八区<br />$mail = new PHPMailer(); //建立邮件发送类<br /><br />$address = "15602277510@163.com";<br />$mail->IsSMTP(); // 使用SMTP方式发送<br>$mail->CharSet ="UTF-8";//设置编码,否则发送中文乱码<br>$mail->Host = "smtp.qq.com"; // 您的企业邮局域名<br>$mail->SMTPAuth = true; // 启用SMTP验证功能<br>$mail->Username = "461147874@qq.com"; // 邮局用户名(请填写完整的email地址)<br>$mail->Password = "**********"; // 邮局密码<br><br>$mail->From = "461147874@qq.com"; //邮件发送者email地址<br>$mail->FromName = "dwqs";<br>$mail->AddAddress($address, "dwqs");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")<br>//$mail->AddReplyTo("", "");<br><br>//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件<br>//$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式<br><br>$mail->Subject = "验证邮件"; //邮件标题<br>$mail->Body = "Hello,这是测试邮件"; //邮件内容<br>$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略<br><br>if(!$mail->Send()) {<br>    echo 'Mailer Error: ' . $mail->ErrorInfo;<br>  } else {<br>  echo "Message sent!恭喜,邮件发送成功!";<br>  }<br>?>

Test results:

(PHP) The email was sent successfully using PHPMailer. I hope to do the following operations. I hope you can provide code or ideas

1 First make a common email login address data
2 Determine the user’s email service provider based on the user’s email suffix
3 The web page will give a prompt or jump.

How to send mass emails with phpmailer? - Technical Q&A

After setting the parameters of PHPMAILer, there is one step to add recipients, right? This assumes that your recipient list is stored in the array $aMails: [php]$mail){? ? ? ? $oMail->SetAddress($mail);}$oMailer->Send();?> [/php]However, I would like to remind you that it is best to use Sendmail to send mass emails to avoid failure to send. Don't send too many emails each time to avoid timing out. You can use the paging principle to send in batches.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/898293.htmlTechArticleUse PHPMailer to share the email sending code. phpmailer email sending is a commonly used function. LZ also used it in the project today. I came across it and would like to share it. First, go download PH...
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