PHP Mail script not working in DB Query

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
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

PHP Mail script not working in DB Query

Post by simonmlewis »

Apart from the lacking PDO, is there any obvious reason why this won't send an email out?
Our registration script works and sends email, but this won't. And it's the same script.

Code: Select all

$result = mysql_query ("SELECT * FROM admin WHERE id='$id'");
      while ($row = mysql_fetch_object($result))
        {
$to = "$row->email";
        $subject =  "Account Active";
        $headers = "From: info@domain.co.uk";
        $body = "Dear $firstname

We are pleased to announce that your account is now active.

Welcome.
To login, simple go to the website, and click the Login link at the top.


Kind regards       
";
        mail ($to, $subject, $body, $headers);
    }    
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Mail script not working in DB Query

Post by Celauran »

Same environment? Is it not being sent or not being received? Anything in the mail server logs? Have you checked that $row->email contains values?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Mail script not working in DB Query

Post by Christopher »

Yes, have you checked if mail() works at all -- with any email address. Check the logs as mentioned. How about the return value for mail()?
(#10850)
Post Reply