phpmailer發(fā)送gmail郵件實例詳解
更新時間:2013年06月24日 10:56:58 作者:
本篇文章是對phpmailer發(fā)送gmail郵件實例進行了詳細的分析介紹,需要的朋友參考下
復制代碼 代碼如下:
<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中使用ExcelFileParser處理excel獲得數據(可作批量導入到數據庫使用)
使用ExcelFileParser處理excel獲得數據 可以用作批量導入到數據庫使用,需要獲取excel數據的朋友可以參考下。2010-08-08
php class中self,parent,this的區(qū)別以及實例介紹
我容易混淆public,private,protected,還容易混淆this,self這些東西。前面已經寫了一篇關于public,private,protected 博文了,下面來說一下this,self,parent的用法2013-04-04
php注冊系統(tǒng)和使用Xajax即時驗證用戶名是否被占用
這篇文章主要為大家詳細介紹了php注冊系統(tǒng)和使用Xajax即時驗證用戶名是否被占用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08

