This is a topic that could be in either PHP, Hosing or Server Config.
I have a few php scripts on a site that (should) send Emails out.
I believe the scripts are fine and do work, they did all work perfectly in the not distant past.
But just lately I have noticed that some scripts are not sending mail.
Some seem to still be working OK, some seem to work some of the time, and one (the contact form) no longer seems to work at all.
I can’t make any sense of it. The contact form script does have the mail function in an if statement to record if there is a problem. The script also records the contact info to a database along with whether the function returned true. What is recorded in the database does not indicate any problem.
Any ideas why the Emails are not being sent?
I’m guessing it must be something the host changed, as everything worked perfectly earlier.
$sql = $db->query("SELECT id, Email FROM People WHERE id IN $recip");
if($sql->rowCount()) {
while($row = $sql->fetch()) {
if(mail($row['Email'], $sub, $mess, $headers)) { $sent[] = $row['id']; }
else { $notsent[] = $row['id'] ; }
}
}
A snippet of code from the form mail script. Returns true every time.
Note, the array of recipient IDs ($recip) is only 2 to 4 people, not hundreds.
Have you checked with your host, Sam? I have had a host where they only allowed mail() to be used with certain to or from email addresses, and the email appeared to go successfully. In one case a client’s host disabled the mail() function altogether - although they were given prior warning.
Yeah, or they can institute rules blocking particular ports, if you’re using a VPS, or, or, or… etc. Definitely agree that you should check with the host first, if you’re sure it worked previously and haven’t changed anything.
The form mail script does use the address the user fills in as the “from”, so it is effectively spoofing (in a legitimate sort of way). But it did previously work and I have already tried changing the the from to something else.
The strange thing is the inconsistency, the scripts that will work one time, but not another.
Though the form mail is the only one that seems to never work now and is the only one that uses addresses that don’t belong to the site.
I just changed the from address to the site admin address and it worked.
But that still does not explain the inconsistent scripts, that are using the exact same from address.
I was having problems on our local server so i would run this to check if it was working or not
` <?php
ini_set( ‘display_errors’, 1 );
error_reporting( E_ALL );
$from = "someone@yoursite.com";
$to = "someone@yoursite.com";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Something to show on the page";
?>`
When the mail function wasn’t working i’d get an error message saying what wasn’t working.
I had already tried a test script, but thought I would have another go with your example.
The results are still confusing.
First go I used the admin address as from, it worked.
Next I changed the from to my hotmail address (spoofing my own account) and that worked too.
could your host server be having intermittent issues? When we had a period of issues i’d just have that script on a page that i could run a couple of times a day to see when it was and wasn’t working. If you’ve changed nothing and it goes from working to not working it’ll show you if it’s the server messing about.