时时商务社区
标题:
PHP借助phpmailer发送邮件
[打印本页]
作者:
xgnic
时间:
2018-2-14 05:46
本地没有发邮件的服务器,借助现成的SMTP服务器发送邮件是个不错的选择,这里使用到的工具是phpmailer ( Version 5.2.0),SMTP服务器就选gmail和163。
1. 使用gmail发送的脚本
include("class.phpmailer.php");
include("class.smtp.php");
//获取一个外部文件的内容
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
//设置smtp参数
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->
ort = 465;
//填写你的gmail账号和密码
$mail->Username = "yourname@gmail.com";
$mail->
assword = "password";
//设置发送方,最好不要伪造地址
$mail->From = "yourname@gmail.com";
$mail->FromName = "Webmaster";
$mail->Subject = "This is the subject";
$mail->AltBody = $body;
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
//设置回复地址
$mail->AddReplyTo("yourname@gmail.com","Webmaster");
//添加附件,此处附件与脚本位于相同目录下
//否则填写完整路径
$mail->AddAttachment("attachment.jpg");
$mail->AddAttachment("attachment.zip");
//设置邮件接收方的邮箱和姓名
$mail->AddAddress("toname@gmail.com","FirstName LastName");
//使用HTML格式发送邮件
$mail->IsHTML(true);
//通过Send方法发送邮件
//根据发送结果做相应处理
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
2.使用163发送邮件的脚本
只需要更改SMTP配置和账户密码即可,SMTP配置如下
//设置smtp参数
//注意这里不需要ssl协议
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true;
$mail->Host = "smtp.163.com";
$mail->
ort = 25;
在本地wampserver环境下测试通过,需要开启php_openssl 扩展。
以上所述就是本文的全部内容了,希望大家能够喜欢。
您可能感兴趣的文章:
phpmailer在服务器上不能正常发送邮件的解决办法
phpmailer发送邮件之后,返回收件人是否阅读了邮件的方法
PHP邮件发送类PHPMailer用法实例详解
使用PHPMailer实现邮件发送代码分享
thinkphp使用phpmailer发送邮件的方法
汇总PHPmailer群发Gmail的常见问题
phplist及phpmailer(组合使用)通过gmail发送邮件的配置方法
phpmailer简单发送邮件的方法(附phpmailer源码下载)
php使用phpmailer发送邮件实例解析
phpmailer绑定邮箱的实现方法
PHPMailer发送邮件
使用PHPMailer发送邮件实例
PHP插件PHPMailer发送邮件功能
Linux服务器下PHPMailer发送邮件失败的问题解决
PHPMailer使用QQ邮箱实现邮件发送功能
phpmailer发送邮件功能
ThinkPHP3.2利用QQ邮箱/163邮箱通过PHPMailer发送邮件的方法
实例分析PHP中PHPMailer发邮件
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2