[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-09-23
7
Medium Priority
?
266 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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 800 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 111

Accepted Solution

by:
Ray Paseur earned 1200 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 84

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 84

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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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