【 PHP 】发送邮件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010324331/article/details/84289953

PHP发送邮件的示例。
首先下载PHPmailer ,下载地址: https://github.com/PHPMailer/PHPMailer/

<?php
// ini_set("display_errors", "On");
// error_reporting(E_ALL | E_STRICT);
header("content-type:text/html;charset=utf-8");
include './phpmailer/PHPMailerAutoload.php';
// 发送邮件
$mail = new PHPMailer;
$mail -> SMTPDebug = false;
$mail -> isSMTP();    // 通过SMTP协议发送
$mail -> CharSet = "utf-8";    // 设置编码
$mail -> Port = 25;    // 设置端口
// SMTP服务器是否需要验证(验证为true 不验证为false)
$mail -> SMTPAuth = true;
// 设置主机服务器
$mail -> Host = "smtp.qq.com";
$mail -> Username = "*****@qq.com";    // 设置用户名
$mail -> Password = "*****";    // 授权码
$mail -> From = "***@qq.comt";    // 发送者是谁
$mail -> FromName = "简书";    // 发送者名称是谁
$mail -> AddAddress("liu******@163.com","烟雨弥漫了江南");
$mail -> ISHTML(true);    // 默认参数就是true
// $mail -> AddAttachment("");    // 这里可添加附件地址
$mail -> Subject = "测试邮件";    // 添加主题
$mail -> Body = "<p>这是测试邮件</p>";    // 正文
if(!$mail->send()) {
	echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
	echo '邮件发送成功';
}

猜你喜欢

转载自blog.csdn.net/u010324331/article/details/84289953