Home> php教程> php手册> body text

phpmailer使用163邮件发送邮件例子,phpmailer163

WBOY
Release: 2016-06-13 09:24:53
Original
933 people have browsed it

phpmailer使用163邮件发送邮件例子,phpmailer163

注意:如果你的服务器安装了卖咖啡并且开户病毒最大防护功能我们需要关闭一个邮件防护哦,否则你的邮件发不出去给被这款杀毒给拦截哦。

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->Port = 465;
//填写你的gmail账号和密码
$mail->Username = "yourname@gmail.com";
$mail->Password = "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"(www.111cn.net));
//添加附件,此处附件与脚本位于相同目录下
//否则填写完整路径
$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->Port = 25;

在本地wampserver环境下测试通过,需要开启php_openssl 扩展。

经验分享

有一些朋友参考此教程来使用sina邮件登录发送邮件时你发现新浪邮件并不支持这个功能,其实这个并不是新浪邮箱不支持此功能我们需要在新浪邮箱中找开pop3这个协议才可以,开户方法是登录新浪之后,我们在右边的更多旁边有一个设置按钮,我们点击进入之后会看到有个“帐户设置”进入之后在最下面有一个pop3协义类的我们可以把它开户,这样你再试一下上面代码就可以解决了哦,有朋友部为什么163邮件不用设置呢,因为163邮件默认是打开pop3的哦。
from:http://www.111cn.net/phper/php-cy/61846.htm

在windows2003上使用phpmailer发送 163邮件 发送不了 提示Could not connect to SMTP host

你可以再 Windows 2003 上 telnet SMTP host 25 值是否通
163的SMTP 应该是 smtp.163.com 具体看你定义的值了。

telnet smtp.163.com 25

phpmailer发送163的邮件,中文全是乱码的,换成什utl-8与gbk都不管用,解决办法?

注意php文件的编码

在发送的时候 也要设置编码
date_default_timezone_set("Asia/Shanghai");//设定时区东八区

$mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置

Related labels:
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!