PHPMailer implements email sending

WBOY
Release: 2016-07-28 08:28:14
Original
1081 people have browsed it

Many times, we need to send emails to our members, such as registration activation, event push, etc.

There are many ways to send emails in PHP, such as the newer Swift Mailer, PHPMailer, etc. Here we mainly introduce the email sending class of PHPMailer.

Download

PHPMailer’s GitHub address: https://github.com/PHPMailer/PHPMailer

implementation

The code is as follows

php //引入类文件 require_once 'PHPMailerAutoload.php'; //实例化类$mail=new PHPMailer(); //是否开始debug模式$mail->SMTPDebug =1; //这里的数字表示提示错误的的类型//使用STMP服务$mail->isSMTP(); //声明发送者邮箱SMTP服务器地址$mail->Host ='smtp.163.com'; //这个是163邮箱SMTP服务器地址//开启SMTP认证$mail->SMTPAuth =true; //发送邮箱帐号$mail->Username ='admin'; //发送邮箱密码$mail->Password ='admin'; //注意这个密码可能不是平时登入时所用的密码,一般邮箱服务商为提供一个授权码,使用时填写这个授权码//加密协议$mail->STMPSecure ='SSL'; //端口号$mail->Port =25; //发送者邮箱和昵称$mail->setFrom('from@163.com','Admin'); //接受者邮箱和昵称$mail->addAddress('to@163.com','Customer'); //是否开启HTML格式$mail->isHTML(true); //设置邮件的字符编码,不然中文乱码$mail->CharSet='UTF-8'; //邮件主题$mail->Subject ='subject'; //邮件内容$mail->Body ='body'; //邮件替代内容$mail->AltBody ='altbody'; //当邮件不支持html时备用显示,可以省略 //邮件附件$mail->addAttachment('load.zip'); if(!$mail->send()){ echo 'Message could not be sent'; echo 'Mail Error:'.$mail->ErrorInfo; }else{ echo 'Message has been sent'; } 
Copy after login

The blogger has personally tested it and it is effective. You can learn step by step by watching the code

Here I point out a few issues

  • Introduction of class files
    After you download it from git or use composer to download it, you will get a lot of files. You only need to import this file.PHPMailerAutoload.php
  • SMTP server address and port number
  • Generally we need to enable the SMTP service in the email settings.
    NetEase’s email address is as follows:

    PHPMailer实现邮件发送For other email addresses, you can use Baidu or Google, so I won’t go into details here.
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); The above has introduced how to implement email sending with PHPMailer, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!