phpmailer發(fā)送gmail郵件實(shí)例詳解
更新時(shí)間:2013年06月24日 10:56:58 作者:
本篇文章是對phpmailer發(fā)送gmail郵件實(shí)例進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
復(fù)制代碼 代碼如下:
<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>
您可能感興趣的文章:
相關(guān)文章
PHP常用排序算法實(shí)例小結(jié)【基本排序,冒泡排序,快速排序,插入排序】
這篇文章主要介紹了PHP常用排序算法,結(jié)合實(shí)例形式總結(jié)分析了php常見的排序算法,包括基本排序、冒泡排序、快速排序、插入排序等,需要的朋友可以參考下2017-02-02php實(shí)現(xiàn)數(shù)組按拼音順序排序的方法
這篇文章主要介紹了php實(shí)現(xiàn)數(shù)組按拼音順序排序的方法,涉及php漢字與拼音的轉(zhuǎn)換及數(shù)組遍歷、排序相關(guān)操作技巧,需要的朋友可以參考下2017-05-05如何阻止網(wǎng)站被惡意反向代理訪問(防網(wǎng)站鏡像)
最近有人用小站數(shù)據(jù),利用反向代理技術(shù),做了個小偷站。用戶訪問的是他的網(wǎng)址,但實(shí)質(zhì)上內(nèi)容數(shù)據(jù)確是我的,這是一起惡意反向代理事件2014-03-03PHP pthreads v3下同步處理synchronized用法示例
這篇文章主要介紹了PHP pthreads v3下同步處理synchronized用法,結(jié)合實(shí)例形式分析了PHP pthreads v3下同步處理synchronized原理、使用方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2020-02-02