Page 1 of 1

PHP Mail from MySQL

Posted: Tue Oct 07, 2003 12:29 pm
by brianharrell
Mailing from MySQL variable containing users email address fails:

$sendto = $row['emailb'];

$from = "<support@mydomain.com>";
$subject = "Monthly News from MyDomain";

$mss = "Newsletter body";
$mss .= "Thank you \n\n";

mail($sendto, $subject, $mss,"FROM: $from");

$row['emailb'] gets a valid email from MySQL as I have echoed it to the screen to check.

This works just fine:

$sendto = "support@mydomain.com";

$from = "<support@mydomain.com>";
$subject = "Monthly News from MyDomain";

$mss = "Newsletter body";
$mss .= "Thank you \n\n";

mail($sendto, $subject, $mss,"FROM: $from");

This works fine also

$sendto = "support@mydomain.com,".$row['emailb'];

$from = "<support@mydomain.com>";
$subject = "Monthly News from MyDomain";

$mss = "Newsletter body";
$mss .= "Thank you \n\n";

mail($sendto, $subject, $mss,"FROM: $from");

I just can't get the email to send if I use a variable from MySQL

Thanks!

Posted: Tue Oct 07, 2003 3:03 pm
by wmasterj
i'm not totally sure, but i myself haven't been able to send email outside the domain specified in the POP3 and the SMTP.
ex. mail.domain.com

Maybe that's the problem ? ?)

Anybody know how to solve this??

Posted: Tue Oct 07, 2003 4:11 pm
by qads
are you sure your useing a loop to send emails? or are you just trying to send 1 email? if you have more then 1 email then you will have to loop to get each email and send it off. e.g.

Code: Select all

<?php
$query = mysql_query("select email from table");
while($row = mysql_fetch_array($query))
{
mail($row[email], $subject, $message, $extra_headers);
}
?>

that would do it ^^^^

Posted: Tue Oct 07, 2003 7:00 pm
by Cruzado_Mainfrm
check in the php.ini file if you have set the SMTP server correctly, i think it's in the SMTP or MAIL section, ex.: [MAIL]