I am trying to switch a webpage from regular PHP mail to PEAR mail. On this page I want the email sent to a recipient who is entering their email into a web form. I am trying to set the $to equal to $pickeremail, as per the code below, but alas, then PEAR tries to send the email to "$pickeremail" rather than to the email that is actually entered in the web form by the user.
$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 = '[email protected]';
$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;
}
}
I added a var_dump, as per the suggestion below, out was:
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) "[email protected]" ["To"]=> string(0) "" ["Subject"]=> string(19) "Pickup Confirmation" } Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 501, response: 5.5.4 Invalid Address)]NULL
I noticed that in the header array I had 'To' => $to, I changed this to 'To' => $recipients. I also changed the line: $pickeremail = mysql_result($result,$i,"picker_email"); to:$pickeremail=$_POST['pickeremail']; Now, I am getting the this 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) "[email protected]" ["To"]=> string(20) "[email protected]" ["Subject"]=> string(19) "Pickup Confirmation" } Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 501, response: 5.5.4 Invalid Address)]NULL