PHP Mail from MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brianharrell
Forum Newbie
Posts: 5
Joined: Tue Mar 11, 2003 10:36 am
Location: MN USA

PHP Mail from MySQL

Post 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!
User avatar
wmasterj
Forum Commoner
Posts: 40
Joined: Mon Aug 18, 2003 5:52 pm
Location: Stockholm, Sweden

Post 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??
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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 ^^^^
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post 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]
Post Reply