Jump to content

PHP mail


jandrews3

Recommended Posts

I have a simple php mail statement pulled from a database for about 1200 members of an organization. It worked perfectly on the previous server I had it on, but since we've moved to a new server I'm getting an odd result. I'm getting some (about a quarter) emails sent and a failure to send on the others. With the script run several times, I get different results. For example, on the first run, Bob's email might get sent, but on the second one his is one of the failures. Below is the brunt of the script. I don't believe the problem is in the script but rather something with the server. Has anyone had a problem like this, or have any idea of what it may be? THANK YOU!!!

 

  $query1 = "SELECT * FROM ithf_members WHERE email != '' ORDER BY lname, fname";
  $result1 = mysql_query($query1) or die("Could not perform query: ".mysql_error());

		$fset = "-fpkomornik@ithf.org";
      $count = 0;
    if ($recip == 1){
    	while ($row1 = mysql_fetch_array($result1)) {
    		if ($row1['active'] > 1){
    				$to = $row1['email'];
    				$subject = $subj;
    				$body = $msg;
						$headers = "From: pkomornik@ithf.org\r\n" .
				  	  	"X-Mailer: php\r\n".
				 		  	"Return-Path: pkomornik@ithf.org\r\n";
				 		if (mail($to, stripslashes($subject), stripslashes($body), $headers, $fset)) {echo("<p>Sent to ".$row1['fname']." ".$row1['lname']." at ".$row1['email']."</p>");}
				 		else {echo("<p>Failed to send to ".$row1['fname']." ".$row1['lname']." at ".$row1['email']."</p>");}
    				$count++;
    			}
    	}
    }

Link to comment
Share on other sites

I'm getting some (about a quarter) emails sent and a failure to send on the others.

 

the mail function might be disabled on the server if your host is not willing to configure php.ini to enable it.

 

If that was the case, wouldn't it stand to reason that NONE of the emails would be sent?

Link to comment
Share on other sites

Yes, I would have expected none of them to send. However, each time the script runs, I get a random set of "sends" and a random set of "failures." I have several other mail() statements on other pages. But it is this massive repetitive script (looping through the entire membership sending over 1000 emails) which fails.

Link to comment
Share on other sites

It's really strange. A bunch will send successfully starting out, then a couple hundred will fail. Then again another set of 30 or 40 send properly followed by another set of a few hundred failures. There are also examples of individual successful sends scattered inside large blocks of failures. I would think something was wrong with the script or the data but for the fact that 1) the script worked perfectly on our previous server, and 2) which email fails and which succeeds appears to be random after having run the script several times.

 

One test I ran was to manually change the "send to address" in the code from the variable $to to my own email address ... so each time the loop cycled it would look like it was sending to the member, but it would actually send to me. The script ran without problem and I received the expected 1169 emails. But when changed back to the $to variable, the random failures popped up again. Auuugggghhhh!

Link to comment
Share on other sites

This is a complete shot in the dark, but why don't you try delaying the time between emails a bit (in this case 1/20 of a second). Maybe something is getting bogged down. Try using:

 

usleep(50000);

 

right before your email call.

 

I almost suggested that too, because that's fixed an issue I've had in the past, but this

 

One test I ran was to manually change the "send to address" in the code from the variable $to to my own email address ... so each time the loop cycled it would look like it was sending to the member, but it would actually send to me. The script ran without problem and I received the expected 1169 emails. But when changed back to the $to variable, the random failures popped up again. Auuugggghhhh!

 

makes it sound like that's not it; at least to me. More like the addresses aren't getting populated (or all of them at least). Or that the script doesn't like the way they're formatted.

 

@OP Do you get the messages produced by the if/else at the end? If so, what do the addresses say (for the failed ones)? Are they populated and/or valid?

Link to comment
Share on other sites

2 questions. Firstly, does anyone know if the bug with the mail function was ever fixed? I never heard anything of it after a while and if not it could be the cause. Secondly, there may be some sort of dns issue perhaps? Sometimes it's resolved successfully, and others its not?

Link to comment
Share on other sites

I'm afraid I don't know the answer to either of your questions. I'm too amateur to know even that there had been a problem with the php mail() function. I had never heard that, but then maybe I had always been using an older php version. The second question, a dns problem? I don't know. I would have thought if there were a dns problem that the failed emails should be consistent, but they're not. My mail scripts which send singular emails have not had this problem. But then the first 50 to 100 emails in this script always seem to successfully send. I'm going to try the delay thing. I wondered if something like that might be happening.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.