任何幫助將不勝感激。下面是代碼:PHP電子郵件腳本無法正常工作。怎麼了?
<?php include 'header_admin.php'; ?>
<?php
include 'dbc.php';
page_protect();
checkAdmin();
?>
<?PHP
require_once "Mail.php";
$con = mysql_connect("host","username","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$elist = mysql_query("SELECT cEmail FROM tblUsers WHERE intUserID = '20'");
$from = "FROM E-MAIL";
$subject = $_POST['eSubject'];
$body = $_POST['eMessage'];
$host = "smtp.domain.com";
$port = "465";
$username = "username";
$password = "password";
echo "<div class='entry'>";
if(mysql_num_rows($elist) > 0)
{
while($eresult = @mysql_fetch_array($elist)) {
$headers = array ('From' => $from, 'To' => $eresult['cEmail'], 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($elist_result['cEmail'], $headers, $body);
}
}
echo "<table align='center'><p>Message successfully sent!</p></table></div>";
mysql_close($con);
?>
我確信,SMTP設置是正確的,我手動檢查了我的MySQL查詢,以確保它抓住的e-mail地址。另外,我做了一個單獨的「回聲」命令,以確保$ body和$ subject是正確的。
當你說它「不工作?」時,你是什麼意思?有錯誤消息嗎?你有沒有檢查你的錯誤和郵件日誌文件? – 2010-10-27 05:10:20
如何檢查日誌文件。沒有錯誤。我沒有收到電子郵件。我通過gmail服務器檢查了smtp,它正在工作,只是不通過這個腳本 – BigMike 2010-10-27 05:17:00
可能是你的ISP忽略你的PC發出的smtp協議 – lock 2010-10-27 05:21:54