非常感谢任何帮助。这是代码:
<?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查询,以确保它抓取了电子邮件地址。另外,我做了一个单独的“回声”命令,以确保$ body和$ subject是正确的。
答案 0 :(得分:0)
尝试使用PHP邮件功能:http://php.net/manual/en/function.mail.php
答案 1 :(得分:0)
您使用$elist_result['cEmail']
,如果它与$eresult['cEmail']
不同,它来自哪里?
从上面发布的代码中看不出来。(猜它只是打字错误)
答案 2 :(得分:0)
$smtp->send()
方法返回PEAR_Error对象(如果某些内容爆炸)(如果调用成功,则返回布尔值TRUE)。将您的代码更改为以下内容:
$ret = $smtp->send();
if ($ret !== TRUE) {
echo "Mail send failed: ", $err::getMessage();
}
应该反映出失败的任何细节。