...

View Full Version : Php mail not working anymore - no error message



KatieK
04-17-2012, 04:07 PM
So I've been using php mail() for a while now to send out an email notification to a mailing list located in mysql everytime a newsletter is uploaded to the same database.

For some reason it is not working anymore, but I'm not getting any error message and still receive the success message confirming the emails were sent after uploading a newsletter. The emailing list in mysql has over 400 emails, so I'm wondering if that has something to do with it...
Any help would be appreciated, here's my code, it runs after the code to upload the newsletter



<?php
mysql_connect("servername", "dbusername", "dbpassword") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$result = mysql_query("SELECT email FROM email_list") or die(mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$email= $row['email'];
if(isset($_POST['upload'])){
if($goodtogo =="alliswell"){

$headers = "From: email@email.com\r\nContent-type: text/html";

$message = "<html><body><center>
<table border='0' bgcolor='#8a6754' width='850'>
<tr><td align='center'><img src='http://website.com/images/logo.png'></td></tr>
<tr><td align='center'><font color='#ffffff' face='Arial'>The newsletter for website.com has been updated. To view it, <a href='http://website.com/newsletter.php'>click here</a><br><br><br>


<em>Adobe Acrobat Reader is needed to view this newsletter. To download this free software click the link below</em><br>

http://get.adobe.com/reader<br><br>

</font></td></tr>
</center></body>
</html>";

$mail= mail("$email", "Subject", $message, $headers);

}}}
echo "<font color='#ffffff'><br><em>A notification was successfully sent to the mailing list.<br></em></font>";
?>

Fou-Lu
04-17-2012, 04:12 PM
There's no confirmation that the mail was queued.
You need to contain the results of the mail. If its ever false, something went wrong with the queue.
I'd add a $bResult to it. Default it to true. If $mail is ever false, set $bResult to false.
After the loop, check what $bResult is. If its false, one or more mail() failed. If you want more data, you can use an array of $mail to track results of each one.

If these register successful, the problem is not with PHP, but with SMTP configuration or machine security.

KatieK
04-17-2012, 04:56 PM
$bResult was returned false after the mail function, but how do I go about building an array to tell what the problem was?

Fou-Lu
04-17-2012, 05:30 PM
$bResult was returned false after the mail function, but how do I go about building an array to tell what the problem was?



$aResult = array();
.....

$aResult[] = mail(....);

$aResult will be an array with each entry added numerically. You could add an associative offset for something like the address.
Chances are, if one returns false, they all return false. Sounds like the sendmail may not be configured properly, so you'll need to contact your host.


BTW, you can never be sure of the problem with mail() from PHP. All you can tell is if it queued or not with the sendmail program in use. If its successful, it has queued, otherwise it has failed. Beyond what PHP can do, its the sendmail's job to actually send the email, and PHP has no way to determine if that was successful from the mail() function.

KatieK
04-17-2012, 05:59 PM
How do I know what sendmail program I'm using though?

Any ideas why this would become a problem all of the sudden when everything has worked fine for so long?

Fou-Lu
04-17-2012, 06:51 PM
If you're hosting your own server, you can check the sendmail using the command line or gui tools. If your on windows, it'll be a separate program that requires configuring with php.ini to configure the proper smtp ports.
If you ar ehosted, contact your host to inform them sendmail doesn't appear to be working. Its possible that they have altered the sendmail path without updating ini, or changed how you are to send email.

KatieK
04-18-2012, 10:55 PM
I'm waiting to hear back from our host concerning php mail settings, but I noticed that when I try to use this form on a different computer I get an actual php error. Says 'No recipient addresses found in header'. But when I echo the $email variable the emails do display so I'm not sure what its referring to...

Any ideas?



Heard back from our host and I guess the problem is we reached the max for emails we could send out per day which is 1000. thanks for your help

KatieK
04-19-2012, 11:30 PM
Sorry to keep reopening this but we found out the problem we had isn't resolved. Even when we're within the 1000 relays/day limits the php mail isn't working. We receive the message saying 'No recipient addresses found in header'.

Any ideas on why this error would suddenly pop up when it's been working fine for months and what we can do to make it work again?

Fou-Lu
04-19-2012, 11:46 PM
Consistently or periodically?
Periodically would indicate that the problem is with your data; in particular that the email address doesn't exist (I think the error for malformed is different). If its a matter of having empty email addresses, I'd address the cause of the empty email addresses, but a temporary solution would be to add a where clause indicating NOT email IS NULL and email <> ""

KatieK
04-20-2012, 12:42 AM
We've never had this problem before, but I did notice there are some empty email addresses. They've been there a while though and didn't cause any problems before. I will try limiting results to only emails that aren't blank and see if that does anything.

tangoforce
04-20-2012, 02:06 AM
We've never had this problem before, but I did notice there are some empty email addresses. They've been there a while though and didn't cause any problems before. I will try limiting results to only emails that aren't blank and see if that does anything.

That indicates that your php configuration has changed and previously you simply didn't know that you had mail failures for individual addresses.

KatieK
04-20-2012, 09:11 PM
I'm not able to test this out yet as we have to wait 24hr for our max relays to reset, will be able to in a couple hours.

The thing is I'm pretty sure the blank email fields in the database aren't the problem because they've been there a while and the problem just now started showing up. And it's not that there's mail failures for only the emails that are empty, none of them are sending out.

Fou-Lu
04-20-2012, 09:24 PM
I'm not able to test this out yet as we have to wait 24hr for our max relays to reset, will be able to in a couple hours.

The thing is I'm pretty sure the blank email fields in the database aren't the problem because they've been there a while and the problem just now started showing up. And it's not that there's mail failures for only the emails that are empty, none of them are sending out.

If no emails are sending, why are you waiting for the max daily sends to reset?

KatieK
04-20-2012, 09:31 PM
Because apparently even if we try to send emails out and they don't go through it still counts towards our relays.

Fou-Lu
04-20-2012, 09:40 PM
I'd be demanding a full explanation out of your host. If they are counting non-sent emails it would be time to find a new host.
Also, how do you know that the emails have not been sent?

KatieK
04-20-2012, 09:51 PM
We aren't exactly pleased with our hosting company either and will possibly be transferring to a different company.

We know the emails are not sending because we have included our own emails in the mailing list as well as other people we know and have never received any of the emails.

We also started getting the error message 'No recipient addresses found in header', which has never been there before and we haven't altered any of our php code.

Any solutions I've found online for this error message so far aren't applicable as we've already had the recommended fixed code in place.

Fou-Lu
04-20-2012, 10:16 PM
Yeah, I think you may need to seek a new host.
All I know for sure, is that the error you have is coming from sendmail. Why its that way I'm not 100% sure. The email would be the most probable cause.
If your host is counting unsent emails, that tells me they have an issue on their end, and are incapable of determining if mail was sent properly. How they would fix it I haven't a clue.
But it doesn't appear to be your PHP code. You could clean it up a bit, remove redundancy in the loop from static strings, and verify emails and whatnots, but all and all it looks like it will run properly.

tangoforce
04-21-2012, 01:29 AM
We also started getting the error message 'No recipient addresses found in header', which has never been there before and we haven't altered any of our php code.


I've already commented on this. Your hosts php / sendmail configuration has changed. Those blank emails addresses you mentioned earlier were previously not being reported to you but now they are. It's probably always been a problem but because you never saw any error messages you thought it was ok.

Sounds like your host has tinkered with the error reporting settings (and a few others).

KatieK
04-23-2012, 11:03 PM
Thanks, it makes sense now why that error started popping up out of nowhere. Problem is even when we change the query to only get the emails that aren't blank none of the emails send. We don't get the 'no recipiants' message anymore but the php mail still isn't working.

It seems like the problem is on our hosting company's end but they aren't cooporating and insist nothing has changed.

Fou-Lu
04-23-2012, 11:08 PM
Thanks, it makes sense now why that error started popping up out of nowhere. Problem is even when we change the query to only get the emails that aren't blank none of the emails send. We don't get the 'no recipiants' message anymore but the php mail still isn't working.

It seems like the problem is on our hosting company's end but they aren't cooporating and insist nothing has changed.

Don't forget you don't need to actually send email. Log the results to a file instead of mailing to see what's going on, or even print them to the screen.

Yeah, to me it still reeks of the host configurations, and its almost like their not sure what they did to break it.

tangoforce
04-24-2012, 12:45 AM
Sounds to me like a host operating from a space PC in the basement if you ask me!

KatieK
04-24-2012, 12:54 AM
So now we were told we need to specify the relay server in our code for this to work. I have the server address given to us but i'm not sure how to go about adding it. Any ideas?

Our host is godaddy by the way, from hours spent online looking into this it's a common problem people have with them and everyone seems to solve the problem in a different way. Sigh..

tangoforce
04-24-2012, 01:08 AM
Switch to PHPMailer instead. It's a class that supports not just sendmail but also SMTP relays such as the one your host has specified.

Fou-Lu
04-24-2012, 02:28 PM
Yeah, phpmailer will use direct sockets to manage the mail I believe.
As for godaddy, yes these have been hit or miss. I've seen half of the posts working with godaddy mail() and the other half not (not just you, user wise).
What they want you to do is pass the information required over to a script that sends. I don't know the fields I'm afraid, but they should have a FAQ with what you can use. You can do it directly by changing your form action to point at their scripts, or you can submit your forms, and use curl to submit it to their forms. For what you have here, you'd need to curl (I'm pretty sure if I recall previous posts on their forms, it is passed by post). I'd suspect that you'll have a full FAQ and tutorial somewhere on their site to guide you through setting this up.

bcarl314
04-24-2012, 02:41 PM
Have you tried using the optional sendmail flag (-f)?



$mail = mail("someone@example.com","subject","my message","From: mycompany@example.com","-fmycompany@example.com");

KatieK
04-26-2012, 09:46 PM
After messing around with this for a while I've found some php mail code that works. Can't say I understand why this works and our other code didn't but it's posted below. Thanks all



mysql_connect("dbserver", "dbusername", "dbpassword") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
$result = mysql_query("SELECT email FROM email_list WHERE email != '' ") or die(mysql_error());


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {


$email= $row['email'];
if(isset($_POST['upload'])){
if($goodtogo =="alliswell"){

$message = "<html><body><center>
<table border='0' bgcolor='#8a6754' width='850'>
<tr><td align='center'><img src='http://website/images/logo.png'></td></tr>
<tr><td align='center'><font color='#ffffff'>The newsletter for website.com has been updated. To view it, <a
href='http://website.com/newsletter.php'>click here</a><br><br><br>
<em>Adobe Acrobat Reader is needed to view this newsletter. To download this free software click the link below</em><br>
http://get.adobe.com/reader<br><br>
</font></td></tr></center></body></html>";

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type:text/html;charset=utf-8' . "\r\n";
$headers .= 'From: Name <email@email.com>' . "\r\n";
$headers .= 'Return-Path:<email@email.com>' . "\r\n";

$mail= mail("$email", "subject", "$message", "$headers");
}}}
if ($mail) {
echo "<font color='#ffffff'><br><br><em>A notification was successfully sent to the mailing list.<br></em></font>";}
else if (!$mail){
echo "<font color='#ffffff'><br><em>There was an error, please try again later.</em></font>";}
?>

Fou-Lu
04-26-2012, 11:14 PM
Are you sure? The $mail check only occurs after all the looping is complete, so it will only contain the last result of the mail() call.
Not sure why that may change it. Neither the mime or the return-path are required.
You should look into using the Pear mail package. It's better than using mail if you want to bulk it up.

Mike_GoDaddy
04-27-2012, 09:51 PM
After messing around with this for a while I've found some php mail code that works. Can't say I understand why this works and our other code didn't but it's posted below. Thanks all


If you are still having any issues I would be more than happy to look into this issue if you PM me your account number or domain name.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum