Home > Backend Development > PHP Tutorial > How to use PHPMailer to send emails? ? , phpmailer mail_PHP tutorial

How to use PHPMailer to send emails? ? , phpmailer mail_PHP tutorial

WBOY
Release: 2016-07-13 10:16:03
Original
905 people have browsed it

How to use PHPMailer to send emails? ? , phpmailer mail

Source: http://www.ido321.com/1103.html

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)

<span><?php 
    <span>// 必要导入</span>
  <span>require</span>(<span>"class.phpmailer.php"</span>);
  <span>require</span>(<span>"class.smtp.php"</span>);
  date_default_timezone_set(<span>'Asia/Shanghai'</span>);<span>//设定时区东八区</span>
$mail = <span>new</span> PHPMailer(); <span>//建立邮件发送类</span>

$address = <span>"15602277510@163.com"</span>;
$mail->IsSMTP(); <span>// 使用SMTP方式发送</span>
$mail->CharSet =<span>"UTF-8"</span>;<span>//设置编码,否则发送中文乱码</span>
$mail->Host = <span>"smtp.qq.com"</span>; <span>// 您的企业邮局域名</span>
$mail->SMTPAuth = <span>true</span>; <span>// 启用SMTP验证功能</span>
$mail->Username = <span>"461147874@qq.com"</span>; <span>// 邮局用户名(请填写完整的email地址)</span>
$mail->Password = <span>"**********"</span>; <span>// 邮局密码</span>

$mail->From = <span>"461147874@qq.com"</span>; <span>//邮件发送者email地址</span>
$mail->FromName = <span>"dwqs"</span>;
$mail->AddAddress($address, <span>"dwqs"</span>);<span>//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")</span>
<span>//$mail->AddReplyTo("", "");</span>

<span>//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件</span>
<span>//$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式</span>

$mail->Subject = <span>"验证邮件"</span>; <span>//邮件标题</span>
$mail->Body = <span>"Hello,这是测试邮件"</span>; <span>//邮件内容</span>
$mail->AltBody = <span>"This is the body in plain text for non-HTML mail clients"</span>; <span>//附加信息,可以省略</span>

<span>if</span>(!$mail->Send()) {
        <span>echo</span> <span>'Mailer Error: '</span> . $mail->ErrorInfo;
    } <span>else</span> {
   <span>echo</span> <span>"Message sent!恭喜,邮件发送成功!"</span>;
    }
?></span>
Copy after login

Test results:



Next article: How many regrets do you have about your university?

How to configure to use phpmailer locally to send emails?

php failed to send email using phpmailer

The server does not have SMTP

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/899960.htmlTechArticleHow to use PHPMailer to send emails? ? , phpmailer email Source: http://www.ido321.com/1103.html Sending emails is a commonly used function. LZ also encountered it in the project today. Hereby...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template