• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

PHP & MySQL application using Mail() function sends some emails fine, then starts sending blank emails

I am using an application written by someone else using PHP and MySQL.  Part of the application sends out emails (in large quantities) to a list of email addresses that you populate in the software.  It sends them using the PHP Mail() function.  What is happening, is that sometimes the emails hang upon sending.  Many will send, but then the application appears to hang.  It's unclear if the issue is with the application itself, or the server(s) I have it running on.  My first thought was that the emails were being blocked by the smtp server (and institutional server) that they were being sent through -- possibly being mis-identified as spam.  I contacted the smtp server folks, they pulled the logs, and could identify that many successful emails went through, then a series of empty emails were attempting to be sent.  These are completely empty -- the from, the to, the body, etc... all empty, so they never get sent, of course (and never received).  Since many, many places use this software successfully, it's unlike something is wrong in the code (though always possible).  I think something is wrong on my servers -- either with PHP, MySQL, or with memory & cpu resources, etc.  I'm at a loss as to how to troubleshoot the issue.  Does anyone have any thoughts on what might cause this behavior?  How can I narrow down the cause?  Both servers are running Windows 2003 server (IIS & PHP on one, MySQL on the other).  Any help would be greatly appreciated.
0
sah18
Asked:
sah18
  • 3
  • 3
2 Solutions
 
Dave BaldwinFixer of ProblemsCommented:
The most likely place is empty address records in the database.  The second most likely is a flaw in the code where in your situation it doesn't recognize where it should stop.  Or maybe something stops it from filling out the form.  If there was something wrong with your server or the main softwares, it would most likely show up elsewhere also.

The first thing is to keep records of what happens and when.  As you make the records more detailed, you will most likely find a pattern to the problem.  Without records and keeping track, you're just guessing.

And even though "many, many places use this software successfully", the people who installed it on your servers could easily have modified it.  PHP files are just text files.
0
 
sah18Author Commented:
Thanks for your thoughts on this, Dave.  I actually did the software install (and do the updates), and I haven't made any modifications to the code at all.

I did check the backend database, and all the email addresses are populated, and they look correctly formatted (no empties).

I actually have very specific records of what is happening (dates and times).  That is how we were able to get the institution to pull the precise smtp logs to see if they were being blocked on their end.  I don't see any clues in the log files, but I don't know that whatever this problem is is being written to a log file (or throwing an error).  I wondered about this being a timeout issue -- with possibly any of the pieces (PHP, IIS, or MySQL), but have no idea how to determine this.  I'd prefer to try to isolate what the specific problem is before starting to make guesses & changes in the php.ini and my.ini files.

0
 
Ray PaseurCommented:
There are so many ways that email can go wrong that it can be a frustrating thing to try to get right.  As a practical matter, you might consider using a service to send the emails instead of trying to do it yourself.  I use and recommend ConstantContact.com because they always get it right and they are almost embarrassingly inexpensive.

If you want to debug this, you might try these things.

1. Add a one-second sleep() between mail() functions
2. Test the return value from the mail() function
3. Echo the contents of the mail() arguments to the browser and look for blank areas

My guess is that a rapid succession of mail() statements may be exhausting a queue somewhere, but that's just a guess.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dave BaldwinFixer of ProblemsCommented:
"changes in the php.ini and my.ini files."  I never change those files to find a problem, that just confuses the issue.

How many emails are you sending in a batch?  I take it that the SMTP server belongs to someone else?  Your ISP?
0
 
sah18Author Commented:
Thanks again to both of you.  I can't use another method to send the emails -- they are integrated into the software we are using.  I really don't think it has to do with the software or the php coding (possible, but unlikely, as others aren't having issues with the same software).

Users send the emails -- the amount can vary.  When testing, I tried sending smaller amounts and larger amounts.  Smaller amounts always send fine.  Larger amounts (say >100 at a time) may or may not go.  I tried sending 1000 in a batch, just to see how far it would get... it made it through 219, but not further.
The software pauses to send the emails in batches to prevent timeout issues, or spam blocking software from keeping them from going out -- It appears to send in groups of 20 at a time, then pauses.  It may also pause between sends, but I'm not sure about this.

The smtp server belongs to my institution -- IT dept runs it.  The aren't blocking anything on their end, but they do see my server attempting (after a while) to send completely empty emails in the logs.

Ray -- I like your suggestions & think they are something I should try.  Can you help with some simple syntax for carrying them out (reminder, I'm really not a php programmer, but know some php).
0
 
Dave BaldwinFixer of ProblemsCommented:
Have you checked the website for the software?  It's next to impossible to write 'perfect' software and sometimes special conditions bring out an error that wasn't seen before.

Here's the page for sleep() http://us3.php.net/manual/en/function.sleep.php and there is a link for time_nanosleep() near the bottom for smaller increments.  You could put sleep(1); at the end of the loop that sends the emails.
0
 
sah18Author Commented:
I appreciate all the suggestions.  The issue turned out to be something with the PHP version I was running.  I upgraded to the latest version, and the emails are sending out fine now.  I'll split points - thanks again for helping me think through the issues.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now