Solved

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

Posted on 2011-09-23
7
254 Views
Last Modified: 2012-08-14
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
Comment
Question by:sah18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 200 total points
ID: 36591329
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
 
LVL 9

Author Comment

by:sah18
ID: 36592148
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
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 36592657
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
Webinar: Security & Encryption in the MySQL world

Join Percona’s Solutions Engineer, Dimitri Vanoverbeke as he presents “Security and Encryption in the MySQL world” on Thursday, July 6, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36593173
"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
 
LVL 9

Author Comment

by:sah18
ID: 36594058
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
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 36594106
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
 
LVL 9

Author Comment

by:sah18
ID: 36787275
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question