我試圖從我的服務器發送郵件,而他們沒有進入垃圾文件夾時收到的另一端。我做了我的研究,發現我應該試用PHPMailer。從服務器發送郵件php
現在我已經用了整整兩天的時間來瀏覽互聯網,試圖找出解決這個問題的辦法。我想使用Google免費SMTP服務發送電子郵件。但不能讓這個工作。
我得到的只是錯誤消息:無法連接到SMTP主機 在我實際得到錯誤消息之前,大約需要15秒。
據谷歌稱這是怎麼了,我應該設定我的設置:
http://mail.google.com/support/bin/answer.py?answer=13287
這是我的代碼:(同其他10個指引/教程我已經找到)
header('Content-Type: text/html; charset=utf-8');
require_once('../class.phpmailer.php');
require_once('../class.smtp.php');
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->SMTPKeepAlive = true;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->CharSet = 'utf-8';
$mail->Username = '[email protected]'; // SMTP account username
$mail->Password = 'mypw';
$mail->SetFrom('[email protected]', 'My name');
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("[email protected]", "Reciever Name");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
所以這顯然不起作用。我應該接觸我的isp嗎?或者我應該嘗試其他的東西?我真的需要能夠發送電子郵件,而不他們直行到垃圾郵件文件夾...
最好的問候, 亞歷山大
許多ISP阻止訪問外部SMTP服務器作爲垃圾郵件防範措施。您可以使用普通郵件客戶端從運行此腳本的任何地方向Gmail帳戶發送郵件嗎? – 2011-03-22 14:31:58