PEAR邮件,使用Web表单获取$

时间:2012-07-14 17:40:47

标签: php email pear

我正在尝试将网页从常规PHP邮件切换到PEAR邮件。在此页面上,我希望将电子邮件发送给将电子邮件输入网络表单的收件人。我试图将$设置为等于$ pickeremail,根据下面的代码,但是唉,然后PEAR尝试将电子邮件发送到“$ pickeremail”而不是用户实际在网络表单中输入的电子邮件

$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”[“Content-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'=> $收件人。我也换了一行:$ 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,响应:5.5.4无效地址)] NULL

1 个答案:

答案 0 :(得分:2)

你错了:

$to         = '$pickeremail';

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

$to = $pickeremail;

修改

看看转储:

  

["至"] => string(0)""

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