Home > php教程 > PHP源码 > 用phpmailer通过SMTP的方式发送邮件代码详解

用phpmailer通过SMTP的方式发送邮件代码详解

PHP中文网
Release: 2016-05-25 17:13:18
Original
1544 people have browsed it

PHPMailer是一个用于发送电子邮件的PHP函数包。

它提供的功能包括

*.在发送邮时指定多个收件人,抄送地址,暗送地址和回复地址
*.支持多种邮件编码包括:8bit,base64,binary和quoted-printable
*.支持SMTP验证
*.支持冗余SMTP服务器
*.支持带附件的邮件和Html格式的邮件
*.自定义邮件头
*.支持在邮件中嵌入图片
*.调试灵活
*.经测试兼容的SMTP服务器包括:Sendmail,qmail,Postfix,Imail,Exchange等
*.可运行在任何平台之上

使用方法

require("class.phpmailer.php"); //这个是一个smtp的php文档,网上可以下载得到
$mail = new PHPMailer(); //建立邮件发送类
$mail->CharSet = "UTF-8";
$address ="sdasdsadsa@qq.com";
$mail->IsSMTP(); // 使用SMTP方式发送
$mail->Host = "smtp.126.com"; // 您的企业邮局域名
$mail->SMTPAuth = true; // 启用SMTP验证功能
$mail->Username = "sffsdf@126.com"; // 邮局用户名(请填写完整的email地址)
$mail->Password = "123444"; // 邮局密码
$mail->Port=25;
$mail->From = "sffsdf@126.com"; //邮件发送者email地址
$mail->FromName = "在线Q聊";
$mail->AddAddress("$address", "a");//收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
//$mail->AddReplyTo("", "");

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

$mail->Subject = "在线Q聊"; //邮件标题
$mail->Body = "在线Q聊网站欢迎访问"; //邮件内容,上面设置HTML,则可以是HTML

if(!$mail->Send())
{
    echo "邮件发送失败. <p>";
    echo "错误原因: " . $mail->ErrorInfo;
    exit;
}
Copy after login


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 Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template