提问者:小点点

PEAR邮件,使用web表单获取$to


我试图切换网页从普通的PHP邮件到PEAR邮件。在这个页面上,我想把电子邮件发送给一个收件人,他正在把他们的电子邮件输入一个网络表单。我试图将$设置为等于$piceremail,按照下面的代码,但是唉,然后PEAR试图将电子邮件发送到“$piceremail”,而不是用户在网络表单中实际输入的电子邮件。

$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:

数组(6){[“MIME版本”]=

我注意到在标题数组中我必须“To”=


共1个答案

匿名用户

你在这里错了:

$to         = '$pickeremail';

因为当使用简单引号时,里面的php变量不会被解释。将此行替换为:

$to = $pickeremail;

编辑:

查看转储文件:

[“至”]=

将空字符串放入$to。因此,数据库中的picker_email字段似乎是空的。你应该检查一下。