phpmailer发送gmail邮件实例详解

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</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, gets called from within class.phpmailer.php if not already loaded
$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>

相关文章

探讨捕获php错误信息方法的详解

PS:1.捕获PHP语法错误2.严重错误 用正常的 set_error_handle无法捕获此两类错误,这是捕获此类错误的技巧复制代码 代码如下://test.php 页面error_r...

PHP数组操作实例分析【添加,删除,计算,反转,排序,查找等】

本文实例分析了PHP数组操作。分享给大家供大家参考,具体如下: PHP的数组是很重要的一部分。操作示例如下: <?php function br() { echo...

PHP使用curl模拟post上传及接收文件的方法

本文实例讲述了PHP使用curl模拟post上传及接收文件的方法。分享给大家供大家参考,具体如下: public function Action_Upload(){ $th...

基于php实现的php代码加密解密类完整实例

本文实例讲述了基于php实现的php代码加密解密类。分享给大家供大家参考,具体如下: php 代码加密类,大家可以根据自己的需求进行修改,原类如下,该实例在ubuntu下测试没有问题。...

php通过隐藏表单控件获取到前两个页面的url

php通过隐藏表单控件获取到前两个页面的url

自己在学习过程中也遇到了类似的问题: 比如,后台是想做成这样子的: 但是实际则是这样的: 解决方法: 通过隐藏表单控件 <input type="hidden" name...