标签:date name exception 字符串 sbin 下载地址 email wrap att
部分无隐私代码及成功提示
接收邮件情况
提示:一定要正确引入两个php文件,并且创建对象时根据文件的所在位置创建
贴代码
<?php
header("Content-Type:text/html;charset=utf-8");
/**
* Created by PhpStorm.
* User: 张海强
* Date: 2019/1/17
* Time: 11:25
*/
header("content-type:text/html;charset=utf-8");
//正确引入php文件
require 'PHPMailer/SMTP.php';
require 'PHPMailer/PHPMailer.php';
try {
$mail = new \PHPMailer\PHPMailer\PHPMailer();//此处一定要根据实际文件路径创建
$mail->IsSMTP();
$mail->CharSet='UTF-8'; //设置邮件的字符编码,这很重要,不然中文乱码
$mail->SMTPAuth = true; //开启认证
$mail->Port = 25;
$mail->Host = "smtp.163.com";
$mail->Username = "发送者邮件地址";
$mail->Password = "发送者邮件密码";
// $mail->IsSendmail(); //windows下开启;linux下如果没有sendmail组件就注释掉,否则出现“Could not execute: /usr/sbin/sendmail”的错误提示
$mail->AddReplyTo("回复地址","dee");//回复地址
$mail->From = "发送者邮件地址";
$mail->FromName = "发送者名称";
$to = "接收者邮件地址";
$mail->AddAddress($to);
$mail->Subject = "phpmailer测试标题";
$mail->Body = "<h1>phpmail演示</h1>这是emperor对phpmailer的测试内容";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示,可以省略
$mail->WordWrap = 80; // 设置每行字符串的 长度
//$mail->AddAttachment("d:/test.jpg"); //可以添加附件
$mail->IsHTML(true);
$mail->Send();
echo '邮件已发送';
} catch (phpmailerException $e) {
echo "邮件发送失败:".$e->errorMessage();
}
牛贴一篇,点我
标签:date name exception 字符串 sbin 下载地址 email wrap att
原文地址:https://www.cnblogs.com/benjaminfee/p/10281479.html