[size=large][b]简要介绍如何使用PHPMailer通过GMail的SMTP协议发送邮件。[/b][/size]
[color=blue][size=large]下载PHPMailer[/size][/color]
点击 [url=http://adf.ly/2960050/iteyephpmailerdownload]http://phpmailer.sourceforge.net/[/url] 进入PHPMailer在Source Forge的发布页, 或者直接点击 [url=http://sourceforge.net/project/showfiles.php?group_id=26031]下载[/url]。
[color=blue][size=large]解压缩并上传[/size][/color]
将下载下来的PHPMailer压缩包解开,然后将解开的目录和文件上传到可以使用PHP的web服务器。
[color=blue][size=large]发送Gmail的代码样例[/size][/color]
[color=red]关键部分:[/color]
[color=red]完整的样例代码:[/color]
本文镜像: [url=http://www.jiani.info/2012/08/%e4%bd%bf%e7%94%a8phpphpmailer%e5%92%8cgmail%e5%8f%91%e9%80%81%e7%94%b5%e5%ad%90%e9%82%ae%e4%bb%b6/]PHP发送Gmail邮件[/url]
[color=blue][size=large]下载PHPMailer[/size][/color]
点击 [url=http://adf.ly/2960050/iteyephpmailerdownload]http://phpmailer.sourceforge.net/[/url] 进入PHPMailer在Source Forge的发布页, 或者直接点击 [url=http://sourceforge.net/project/showfiles.php?group_id=26031]下载[/url]。
[color=blue][size=large]解压缩并上传[/size][/color]
将下载下来的PHPMailer压缩包解开,然后将解开的目录和文件上传到可以使用PHP的web服务器。
[color=blue][size=large]发送Gmail的代码样例[/size][/color]
[color=red]关键部分:[/color]
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username@gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
[color=red]完整的样例代码:[/color]
function send_by_gmail($to, $subject, $content){
// send mail using PHPMailer
require_once("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom($to, 'username');
$mail->Subject = $subject;
$mail->Body = $content;
$mail->AddAddress($to, "username");
if(!$mail->Send()) {
return array('status'=>true, 'msg'=>"Mailer Error: " . $mail->ErrorInfo);
} else {
return array('status'=>false, 'msg'=> "Message sent!");
}
}
本文镜像: [url=http://www.jiani.info/2012/08/%e4%bd%bf%e7%94%a8phpphpmailer%e5%92%8cgmail%e5%8f%91%e9%80%81%e7%94%b5%e5%ad%90%e9%82%ae%e4%bb%b6/]PHP发送Gmail邮件[/url]