我正在尝试将网页从常规 PHP 邮件切换到 PEAR 邮件。在此页面上,我希望将电子邮件发送给正在将其电子邮件输入 Web 表单的收件人。我正在尝试将 $to 设置为等于 $pickeremail,根据下面的代码,但是,唉,然后 PEAR 尝试将电子邮件发送到“$pickeremail”,而不是发送到用户在 Web 表单中实际输入的电子邮件.
$con = mysql_connect("localhost","BLAHBLAH","BLAHBLAH");
mysql_select_db("schoolh_SHS", $con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$sql = "UPDATE Donations SET `PICKER_NAME`='$_POST[pickername]',`PICKER_EMAIL`='$_POST[pickeremail]',`PICKER_PHONE`='$_POST[pickerphone]',`STATUS`='CLAIMED' WHERE DONATIONID = $_POST[id]";
$q = "SELECT * FROM Donations WHERE DONATIONID = $_POST[id]";
$result = mysql_query($q);
$Donation = mysql_fetch_array($result);
$orgname = mysql_result($result,$i,"orgname");
$address = mysql_result($result,$i,"address");
$city = mysql_result($result,$i,"city");
$state = mysql_result($result,$i,"state");
$pickeremail = mysql_result($result,$i,"picker_email");
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
function send_email($recipients, $from, $subject, $body)
{
require_once "Mail.php";
require_once "Mail/mime.php";
$to = '$pickeremail';
$cc = 'whynoceros@gmail.com';
$recipients = $to.", ".$cc;
$subject = 'Pickup Confirmation';
$from = 'blah';
$host = 'blah';
$username = 'donations';
$password = 'blahblah';
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$mime = new Mail_mime();
$mime->setHTMLBody($body);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array(
'host' => $host,
'auth' => true,
'username' => $username,
'password' => $password
));
$mail = $smtp->send($recipients, $headers, $body);
if (PEAR::isError($mail))
{
//return false;
echo ($mail->getMessage());
}
else
{
return true;
}
}
根据下面的建议,我添加了一个 var_dump,结果是:
array(6) { ["MIME-Version"]=> string(3) "1.0" ["Content-Type"]=> string(29) "text/html; charset=ISO-8859-1" ["内容-Transfer-Encoding"]=> string(16) "quoted-printable" ["From"]=> string(33) "donations@schoolhousesupplies.org" ["To"]=> string(0) "" [" Subject"]=> string(19) "Pickup Confirmation" } 添加收件人失败:@localhost [SMTP:从服务器收到的响应代码无效(代码:501,响应:5.5.4 无效地址)]NULL
我注意到在标题数组中我有'To' => $to,我将其更改为'To' => $recipients。我还更改了行: $pickeremail = mysql_result($result,$i,"picker_email"); 收件人:$pickeremail=$_POST['pickeremail']; 现在,我得到了这个 var_dump: array(6) { ["MIME-Version"]=> string(3) "1.0" ["Content-Type"]=> string(29) "text/html; charset= ISO-8859-1" ["Content-Transfer-Encoding"]=> string(16) "quoted-printable" ["From"]=> string(33) "donations@schoolhousesupplies.org" ["To"]= > string(20) "whynoceros@gmail.com" ["Subject"]=> string(19) "Pickup Confirmation" } 添加收件人失败:@localhost [SMTP:从服务器收到的响应代码无效(代码:501,