Lassie Posted July 31, 2007 Share Posted July 31, 2007 I have a function which generates an email message. The email is sent but not my variable information. i know 4e and $v_id are correctly populated. How can i debug this? function vendor_email($e,$v_id) { $user_id=$v_id; $connection = db_connect(); $query = "select * from users where user_id='$user_id'"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); if (!$result) return false; while($row=mysql_fetch_assoc($result)) { $first_name=$row['first_name']; $last_name=$row['last_name']; } //prepare message $body="The Vendor details you requested are as follows:-\n"; $body.="Name:-"; $body.=$first_name; mail($e, 'Vendor Details', $body, 'From: [email protected]'); } Link to comment https://forums.phpfreaks.com/topic/62650-problem-generating-email/ Share on other sites More sharing options...
soycharliente Posted July 31, 2007 Share Posted July 31, 2007 I don't see anything wrong. Feel free to pick at my code that I've never had problems with. <?php dbconnect(); $query = "SELECT * FROM users WHERE id='$id'"; $result = mysql_query($query) or DIE(mysql_error()); if ($result) { $r = mysql_fetch_assoc($result); $un = $r["username"]; $em = $r["email"]; } dbclose(); $to = $em; $subject = "Registration Complete"; $msg = "<html> <head> <title>Registration Complete</title> </head> <body> <p>Username: $un</p> <p>Password: Not given to protect your account.</p> <p>E-mail: $em</p> <p>This is a one time e-mail to inform you of the information that you gave. You will not get this e-mail again.</p> <p>If you have any questions, contact the webmaster via the site.</p> </body> </html>"; $msg = wordwrap($msg, 70); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; $headers .= "From: Webmaster <[email protected]>\r\n"; // SEND THE EMAIL ini_set(sendmail_from, $email); mail($to, $subject, $msg, $headers); ini_restore(sendmail_from); ?> Also, I don't think you need to use a while loop for a mysql_fetch_assoc. It's returning just one row. You can just take that out of the while loop like you see in the code I gave as an example. Link to comment https://forums.phpfreaks.com/topic/62650-problem-generating-email/#findComment-311830 Share on other sites More sharing options...
Lassie Posted July 31, 2007 Author Share Posted July 31, 2007 Thanks I will have a play Link to comment https://forums.phpfreaks.com/topic/62650-problem-generating-email/#findComment-311843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.