Note that there are some explanatory texts on larger screens.

plurals
  1. POPEAR mail, using web form to get $to
    text
    copied!<p>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.</p> <pre><code>$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' =&gt; $from, 'To' =&gt; $to, 'Subject' =&gt; $subject ); $mime = new Mail_mime(); $mime-&gt;setHTMLBody($body); $body = $mime-&gt;get(); $headers = $mime-&gt;headers($headers); $smtp = Mail::factory('smtp', array( 'host' =&gt; $host, 'auth' =&gt; true, 'username' =&gt; $username, 'password' =&gt; $password )); $mail = $smtp-&gt;send($recipients, $headers, $body); if (PEAR::isError($mail)) { //return false; echo ($mail-&gt;getMessage()); } else { return true; } } </code></pre> <p>I added a var_dump, as per the suggestion below, out was: </p> <blockquote> <p>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" } Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 501, response: 5.5.4 Invalid Address)]NULL</p> </blockquote> <p>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) "donations@schoolhousesupplies.org" ["To"]=> string(20) "whynoceros@gmail.com" ["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</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload