Forum Moderators: coopster
=============================
$row = mysql_fetch_array(mysql_query("SELECT email FROM users WHERE id=$sid"));
$to = '$email';
$subject = '$subject';
$message = '$message.';
$headers = 'From: blah@domain.com';
mail($to, $subject, $message, $headers);
===============================
This is what i have to open the db and get the info, but I'm having trouble getting the info to work as intended.
I know something has to go after the fetch line and before the mail function, but I am having trouble as all I've tried is not working. Which would be the best way to go?
also, as far as headers go you should terminate each line with \r\n, so they should be like this
$headers = "From: blah@domain.com\r\n";
you need the double quotes around them so they resolve into carriage return and linefeed instead of being treated as a string.
Below is the code I am using
========================
$row = mysql_fetch_array(mysql_query("SELECT email FROM users WHERE id=$sid"));
$to = $row['email']\r\n";
$subject = 'Subject\r\n";
$message = 'Message';
$headers = 'From: blah@domain.com';
mail($to, $subject, $message, $headers);
your code should actually look like this
$row = mysql_fetch_array(mysql_query("SELECT email FROM users WHERE id=$sid"));
$to = $row['email'];
$subject = 'Subject';
$message = 'Message';
$headers = "From: blah@domain.com\r\n";
mail($to, $subject, $message, $headers);
ok, we have a few things to check before we start firing off emails so we will comment that line and add a few echo's to figure out if our vars are being set properly.
$row = mysql_fetch_array(mysql_query("SELECT email FROM users WHERE id=$sid"));
// dump the $row var to the screen to verify row data is retrieved
echo '<p><pre>row: ';
print_r($row);
echo '<pre>';
$to = $row['email'];
$subject = 'My Subject';
$message = 'My Message';
$headers = "From: blah@domain.com\r\n";
// echo all vars to make sure they are set properly
echo '<p>to: ',$to;
echo '<br>subject: ',$subject;
echo '<br>message: ',$message;
echo '<br>headers: ',$headers;
//mail($to, $subject, $message, $headers);
try the above and see if it helps you identify if there are any data problems.
email is a terrible thing to have to work with as their are so many outside factors that effect it. I have control of all the mail servers I send through and there is still the ISP in the mix so it only helps some. At least i an look at the mail queue to see if the message is there.