教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 phpmailer发送gmail邮件的例子

phpmailer发送gmail邮件的例子

发布时间:2016-07-09   编辑:jiaochengji.com
本文介绍下,使用phpmailer发送gmail邮件的例子,有需要的朋友参考下吧。

使用PHPMailer类发送gmail邮件实例代码:
 

<html>
<head>
<title>PHPMailer-发送gmail邮件_www.jbxue.com</title>
</head>
<body>
<?php
//error_reporting(E_ALL);
error_reporting(E_STRICT);

date_default_timezone_set('America/Toronto');

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.gmail.com"; // SMTP server
$mail->SMTPDebug  = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$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   = "***@gmail.com";  // GMAIL username
$mail->Password   = "***"; // GMAIL password

$mail->SetFrom('****@gmail.com', 'First Last');
$mail->AddReplyTo("***@gmail.com","First Last");
$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 = "***@gmail.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>
</body>
</html>

需要引入phpmailer类文件,下载地址:PHPMailer邮件发送类V5.1下载地址。
 

您可能感兴趣的文章:
PHPMailer发送邮件的实例分享
phpmailer发送网易126邮箱的例子
phpmailer发送yahoo邮件的例子
phpmailer类实现邮件群发的实例代码
PHPMailer发送邮件代码实例(ubuntu系统)
PHPMailer发送带附件邮件的例子
PHPMailer收发邮件标题、发件人、内容乱码问题的终极解决方法
PHPmailer发送邮件及乱码问题的解决
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer邮件标题中文乱码的解决方法
PHPMailer邮件类发送邮件举例(163邮箱)
phpmailer 发送邮件中文乱码问题的解决方法总结
phpmailer发送邮件及实现密码找回功能的代码
PHPmailer邮件群发的入门例子
PHPmailer 邮件群发的范例参考
phpmailer发邮件中文乱码问题如何解决
phpmailer 类发送邮件乱码解决方法
PHPMailer批量发送邮件的实例代码
有关phpmailer的用法
php使用phpMailer发送邮件的例子
phpmailer实现的简单openvpn用户认证的代码
PHPMailer 中文使用说明
使用phpmailer发送邮件的例子

您可能感兴趣的文章:
phpmailer发送yahoo邮件的例子
phpmailer发送gmail邮件的例子
phpmailer 类发送邮件乱码解决方法
PHPmailer邮件群发的入门例子
PHPMailer发送邮件代码实例(ubuntu系统)
phpmailer发送网易126邮箱的例子
PHPMailer邮件标题中文乱码的解决方法
PHPMailer发送邮件中文附件名乱码的解决办法
PHPMailer发送邮件的实例分享
phpmailer发邮件中文乱码问题如何解决

关键词: PHPMailer  发送邮件   
[关闭]
~ ~