Home  >  Article  >  Backend Development  >  Introduction to how to send emails using PHPMailer (with code)

Introduction to how to send emails using PHPMailer (with code)

不言
不言Original
2018-08-20 16:19:211842browse

This article brings you an introduction to the method of sending emails with PHPMailer (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Please download PHPmailer from github, or directly from Baidu. It is not difficult. Although there are a lot of things in PHPmailer, we only need

PHPMailer.class.php

PHPMailerAutoload .class.php

SMTP.class.php

Then install phpmailer through composer. This is an example I wrote during testing. It was written directly in the native .php file. In fact, There are also some parameters that are useless, but I have not tested them. Friends are welcome to give advice

Although php provides the mail() function, I do not know how to do it and have not studied it, and PHPMailer is a good one The email sending tool is also very simple to use!

<?php
include("class.phpmailer.php");
include("class.smtp.php");
//实例化
$mail = new PHPMailer();
//设置smtp参数
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
//$mail->SMTPSecure = "SSL";
$mail->Host = "smtp.163.com";
$mail->Port = 25;
//填写你的邮箱账号和密码
$mail->Username = "18681613053@163.com";
$mail->Password = "*********";
//设置发送方,最好不要伪造地址
$mail->From = "18681613053@163.com";
$mail->FromName = "阳台大爷";
//标题,内容,和备用内容
$mail->Subject = "163email";
$mail->Body = "163email body";
$mail->AltBody = "163email!!!纯文本";//如果邮件不支持HTML格式,则替换成该纯文本模式邮件
$mail->WordWrap = 50; // 设置邮件每行字符数
//$mail->MsgHTML($body);
//设置回复地址
$mail->AddReplyTo("18681613053@163.com","yy");
//添加附件,此处附件与脚本位于相同目录下,否则填写完整路径
//$mail->AddAttachment("attachment.zip");
//设置邮件接收方的邮箱和姓名
$mail->AddAddress("704203193@qq.com","FirstName LastName");
//使用HTML格式发送邮件
$mail->IsHTML(true);
//通过Send方法发送邮件,根据发送结果做相应处理
if(!$mail->Send()) {
echo "发送失败: " . $mail->ErrorInfo;
} else {
echo "邮件已经成功发送";
}
?>

Related recommendations:

Use PHPMailer to send emails, phpmailer to send emails

A simple way to send emails with phpmailer (with phpmailer source code download ), phpmailer source code download

The above is the detailed content of Introduction to how to send emails using PHPMailer (with code). For more information, please follow other related articles on the PHP Chinese website!

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