crossbones Posted May 19, 2007 Share Posted May 19, 2007 I am trying to send out a personalized email that gets the recipient's (owner's) name and their password from my database. I can only get the yachtname to pull in, but not the other information I want. I know this should be easy, and the connection seems to be valid, as the yachtname is there, so I'm stumped! Thanks for any help. The code follows: <?php require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->From = "sales@crossbonescharters.com"; $mail->FromName = "Alan & Alanna Godsey"; $mail->Subject = "Contract for $yachtname"; @MYSQL_CONNECT("mysqlxxxx.secureserver.net"); @mysql_select_db("database"); $query = "SELECT owner,email,password FROM Yachts WHERE yachtname=%s"; $result = @MYSQL_QUERY($query); { // HTML body </p>'; $body .= "Dear $owner, <br /><br />" ; $body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser<br />"; $body .= "and log in using your password: $password. If you have questions, please contact us. <br /><br/>"; $body .= "Sincerely, <br /><br />"; $body .= "CROSSBONES CHARTERS <br />"; $body .= "Alan & Alanna Godsey <br />"; $body .= "Toll Free 1-877-922-4802"; // Plain text body (for mail clients that cannot read HTML) $text_body .= "Dear $owner, \n\n"; $text_body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser\n"; $text_body .= "Your password is $password \n"; $text_body .= "Sincerely, \n"; $text_body .= "Alan L. Godsey"; $mail->Body = $body; $mail->AltBody = $text_body; $mail->AddAddress($row_Recordset2['email'], $row_recordset2['owner']); if(!$mail->Send()) echo "There has been a mail error sending to " . $row_recordset2['email'] . "<br>"; if($row->MailType == 'html') { $mailer->Body = str_replace('{owner}', $owner, $htmlBody); $mailer->Body = str_replace('{password}', $passwordr, $htmlBody); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{owner}', $owner, $textBody); $mailer->AltBody = str_replace('{password}', password, $textBody); } else { $mailer->Body = str_replace('{owner}', $owner, $textBody); $mailer->Body = str_replace('{password}', $password, $textBody); } Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/ Share on other sites More sharing options...
AndyB Posted May 19, 2007 Share Posted May 19, 2007 Close, but no cigar. One extra line needed ... and watch the cases in your code - $row_Recordset2 isn't right $result = mysql_query($query); // execute query $row_recordset2 = mysql_fetch_array($result); // abstract data from query resource Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-257145 Share on other sites More sharing options...
crossbones Posted May 21, 2007 Author Share Posted May 21, 2007 Ok, now I'm getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/C/b/C/CbCharters/html/contract_1.php on line 665 Line 665 looks like this: $row_recordset2 = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-258642 Share on other sites More sharing options...
trq Posted May 21, 2007 Share Posted May 21, 2007 password is a reserved word in sql, you also fail to wrap your values in quotes so your query is failing, then because you have no error handling, you get the above error. Change your query to.... $query = "SELECT owner,email,`password` FROM Yachts WHERE yachtname='%s'"; Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-258649 Share on other sites More sharing options...
trq Posted May 21, 2007 Share Posted May 21, 2007 Sorry, just noticed the %s aswell. What do you expect that to select? Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-258650 Share on other sites More sharing options...
crossbones Posted May 22, 2007 Author Share Posted May 22, 2007 I took care of the Warning message. I'm still not getting the resulting email I'm looking for. Following is my exact code, and following that is the exact resulting email. Thanks for your help! Alan <?php require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->From = "sales@crossbonescharters.com"; $mail->FromName = "Alan & Alanna Godsey"; $mail->Subject = "Contract for $yachtname"; @MYSQL_CONNECT("mysql37.secureserver.net"); @mysql_select_db("crossboneschart.Yachts"); $query = "SELECT owner,email,cya_number FROM crossboneschart.Yachts WHERE yachtname='1'"; $result = @MYSQL_QUERY($query); // execute query $row_recordset2 = mysql_fetch_array($result); // abstract data from query resource { // HTML body $body .= "Dear $owner, <br /><br />" ; $body .= "We have recieved a partially executed contract for $yachtname.<br /><br />"; $body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser and log in using your password: $cya_number. For this contract to become a definite booking, you will need to fill in your information and submit it.<br /><br />"; $body .= "If you have questions, please contact us. <br /><br/>"; $body .= "Sincerely, <br /><br />"; $body .= "CROSSBONES CHARTERS <br />"; $body .= "Alan & Alanna Godsey <br />"; $body .= "sales@crossbonescharters.com<br />"; $body .= "Toll Free 1-866-922-4802"; // Plain text body (for mail clients that cannot read HTML) $text_body .= "Dear '{owner}', \n\n"; $text_body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser\n"; $text_body .= "Your password is '{cya_number}' \n"; $text_body .= "Sincerely, \n"; $text_body .= "Alan L. Godsey"; $mail->Body = $body; $mail->AltBody = $text_body; $mail->AddAddress($row_Recordset2['email'], $row_recordset2['owner']); if(!$mail->Send()) echo "There has been a mail error sending to " . $row_recordset2['email'] . ""; if($row->MailType == 'html') { $mailer->Body = str_replace('{owner}', $owner, $body); $mailer->Body = str_replace('{cya_number}', $cya_number, $body); $mailer->IsHTML(true); $mailer->AltBody = str_replace('{owner}', $owner, $textBody); $mailer->AltBody = str_replace('{cya_number}', cya_number, $textBody); } else { $mailer->Body = str_replace('{owner}', $owner, $textBody); $mailer->Body = str_replace('{cya_number}', $cya_number, $textBody); } // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); }?> Subject: Contract for Test Yacht From:Alan & Alanna Godsey <sales@crossbonescharters.com> To: alan@crossbonescharters.com Dear , We have recieved a partially executed contract for Test Yacht. Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser and log in using your password: . For this contract to become a definite booking, you will need to fill in your information and submit it. If you have questions, please contact us. Sincerely, CROSSBONES CHARTERS Alan & Alanna Godsey sales@crossbonescharters.com Toll Free 1-866-922-4802 Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-258786 Share on other sites More sharing options...
lampp Posted May 22, 2007 Share Posted May 22, 2007 Man why not you use Zigmoyd mailer ?? Its too cool and too easy. When I used it, My server didn't have SMTP. So the mail was routed from another server. and I used the group mail class its as easy as 2+2=4. and to determine the group I've used browse class. And then I was a noob I made so many mistakes But Zigmoyd parsed it with Artificial Inteligence. And mail goes directly to INBOX.And its ofcourse faster than PHPmailer. Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-258787 Share on other sites More sharing options...
crossbones Posted May 22, 2007 Author Share Posted May 22, 2007 Thanks, but I'm not looking for a different product to use, I'm pleased with PHP mailer in every way, speed included. I know this should be easy, but I'm missing something, and am hoping for someone to be able to spot it and thus, learn something as well. Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-259058 Share on other sites More sharing options...
lee20 Posted May 22, 2007 Share Posted May 22, 2007 This should do the trick. <?php require("class.phpmailer.php"); $mail = new PHPMailer(); $mail->From = "sales@crossbonescharters.com"; $mail->FromName = "Alan & Alanna Godsey"; $mail->Subject = "Contract for $yachtname"; mysql_connect("mysql37.secureserver.net"); mysql_select_db("crossboneschart.Yachts"); $query = "SELECT owner,email,cya_number FROM crossboneschart.Yachts WHERE yachtname='1'"; $result = MYSQL_QUERY($query); // execute query list($owner, $email, $cya_number) = mysql_fetch_row($result); // abstract data from query resource // HTML body $body .= "Dear $owner, " ; $body .= "We have recieved a partially executed contract for $yachtname. "; $body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser and log in using your password: $cya_number. For this contract to become a definite booking, you will need to fill in your information and submit it. "; $body .= "If you have questions, please contact us. "; $body .= "Sincerely, "; $body .= "CROSSBONES CHARTERS "; $body .= "Alan & Alanna Godsey "; $body .= "sales@crossbonescharters.com "; $body .= "Toll Free 1-866-922-4802"; // Plain text body (for mail clients that cannot read HTML) $text_body .= "Dear {$owner}, \n\n"; $text_body .= "Paste 'http://www.crossbonescharters.com/contract_sign_in.php' into your browser\n"; $text_body .= "Your password is {$cya_number} \n"; $text_body .= "Sincerely, \n"; $text_body .= "Alan L. Godsey"; $mail->Body = $body; $mail->AltBody = $text_body; $mail->AddAddress($email, $owner); if(!$mail->Send()) echo "There has been a mail error sending to " . $row_recordset2['email'] . ""; // Clear all addresses and attachments for next loop $mail->ClearAddresses(); $mail->ClearAttachments(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-259094 Share on other sites More sharing options...
crossbones Posted May 25, 2007 Author Share Posted May 25, 2007 With these changes, I still am getting the same resulting email with the owner's name and cya_number blank. Any other suggestions, please? Quote Link to comment https://forums.phpfreaks.com/topic/52130-phpmailer/#findComment-261660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.