PHP 利用Gmail发送邮件
2010-06-25 13:22
441 查看
系统环境:windows7+wamp5
环境要求:Gmail账号+open_ssl+PHPMailer;
1、默认情况下wamp5是没有打开Open_ssl的,这是需要修改php.ini,将extension=php_openssl.dll前面的分号去掉;
2、下载PHPMailer,
PHPMailer是一个用PHP写的用于邮件发送的类。可以去http://sourceforge.net/projects/phpmailer/上下到最新的版本,我用的事PHPMailer_v5.1。
3、将下好的包解压到服务器上,在包里面有个examples文件夹里面是实例,根据需求我选择了test_smtp_gmail_basic.php,修改其中的部分代码为
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com
"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "test@gmail.com
"; // GMAIL username
$mail->Password = "test
"; // GMAIL password
$mail->SetFrom('test2@gmail.com
', 'test
2
');//邮件发送者
$mail->AddReplyTo("test2@gmail.com
","test2
");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "test3@domain.com
";//邮件接收者
$mail->AddAddress($address, "test
3
");
OK!这样配置就行了,其本身还支持附件的功能,在示例里面有相关的代码。
4、还有一个小问题就是,我文件的的编码为utf-8,当邮件的主题也就是$mail->Subject ,包含有中文的时候接收方看到的事一堆乱码,解决的办法是 $subject = ".........";$mail->Subject = "=?UTF-8?B?".base64_encode(
$subject)."?=
";
5、最后一个问题就是感觉效率比较低,发邮件的时间比较长。
6、在某些情况下邮件正文也会出现乱码,这个需要修改引用文件class.phpmailer.php
public $CharSet = 'iso-8859-1';
/**
* Sets the Content-type of the message.
* @var string
*/
public $ContentType = 'text/plain';
/**
* Sets the Encoding of the message. Options for this are
* "8bit", "7bit", "binary", "base64", and "quoted-printable".
* @var string
*/
public $Encoding = '8bit';
以上配置是对邮件正文的设置,及邮件发送的编码方式等。
环境要求:Gmail账号+open_ssl+PHPMailer;
1、默认情况下wamp5是没有打开Open_ssl的,这是需要修改php.ini,将extension=php_openssl.dll前面的分号去掉;
2、下载PHPMailer,
PHPMailer是一个用PHP写的用于邮件发送的类。可以去http://sourceforge.net/projects/phpmailer/上下到最新的版本,我用的事PHPMailer_v5.1。
3、将下好的包解压到服务器上,在包里面有个examples文件夹里面是实例,根据需求我选择了test_smtp_gmail_basic.php,修改其中的部分代码为
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com
"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "test@gmail.com
"; // GMAIL username
$mail->Password = "test
"; // GMAIL password
$mail->SetFrom('test2@gmail.com
', 'test
2
');//邮件发送者
$mail->AddReplyTo("test2@gmail.com
","test2
");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "test3@domain.com
";//邮件接收者
$mail->AddAddress($address, "test
3
");
OK!这样配置就行了,其本身还支持附件的功能,在示例里面有相关的代码。
4、还有一个小问题就是,我文件的的编码为utf-8,当邮件的主题也就是$mail->Subject ,包含有中文的时候接收方看到的事一堆乱码,解决的办法是 $subject = ".........";$mail->Subject = "=?UTF-8?B?".base64_encode(
$subject)."?=
";
5、最后一个问题就是感觉效率比较低,发邮件的时间比较长。
6、在某些情况下邮件正文也会出现乱码,这个需要修改引用文件class.phpmailer.php
public $CharSet = 'iso-8859-1';
/**
* Sets the Content-type of the message.
* @var string
*/
public $ContentType = 'text/plain';
/**
* Sets the Encoding of the message. Options for this are
* "8bit", "7bit", "binary", "base64", and "quoted-printable".
* @var string
*/
public $Encoding = '8bit';
以上配置是对邮件正文的设置,及邮件发送的编码方式等。
相关文章推荐
- php利用smtp发送邮件
- PHP利用PHPMailer组件的Gmail发信能力发送电子邮件
- 利用asp.net自带邮件组件 发送邮件,支持126,163,gmail,qq等邮箱
- PHP 利用 smtp服务器发送邮件
- PHPMailer邮件类利用smtp.163.com发送邮件方法
- 利用PHPMailer 来完成PHP的邮件发送
- 利用PHPMailer实现PHP邮件发送
- phpmailer发送gmail邮件实例详解
- 利用PHPMailer 来完成PHP的邮件发送
- 利用 Composer 完善自己的 PHP 框架(二)——发送邮件
- 利用PHPMailer 来完成PHP的邮件发送
- PHPMailer IIS下的PHP脚本使用GMAIL发送邮件PHP
- 利用asp.net自带邮件组件 发送邮件,支持126,163,gmail,qq等邮箱
- 利用javamail 发送gmail邮件
- php 利用phpmailer 发送邮件
- phpmailer发送gmail邮件实例详解
- 利用phpmailer发送验证邮件 注册会员
- php 发送邮件教程 发送邮件附带附件 利用PHPMailer发送邮件教程
- php利用phpmailer发送邮件
- PHP 利用QQ邮箱发送邮件「PHPMailer」