The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Bizarre issue sending email with mail function
Discuss Bizarre issue sending email with mail function in the PHP Development forum on Dev Shed. Bizarre issue sending email with mail function PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 26th, 2013, 09:42 AM
|
 |
300lb Bench!
|
|
Join Date: Aug 2001
Location: New York
|
|
|
Bizarre issue sending email with mail function
I have a chess website and email gets sent all the time. For example, if you create a new game, an email gets sent out to their opponent. This is functionality that's been working for years.
Yesterday morning, I woke up to server issues that I eventually realized were being caused every time I tried sending an email. However, when I take the send mail code and run it by itself, it appears to run fine. The code is
PHP Code:
//stuff before
if ($sEmailOfOpponent) {
sendEmail($sSubject,$sMessage,array($sEmailOfOpponent));
}
//stuff after
$sEmailOfOpponent gets set only if the user wants to be notified by email. sendEmail contains
PHP Code:
$sMessage = formatEmailMessage($sMessage);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: support@mywebsite.com' . "\r\n";
$headers .= 'bcc: ' . join(",",$aryRecipients) . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
mail('noreply@nothingbutchess.com',$sSubject,$sMessage,$headers);
formatEmailMessage literally does that. It puts my company logo, wraps the message in a little html, nothing special. I've confirmed that if I comment out the sendEmail call, everything works fine. If I don't, things work.....eventually. 15-20 seconds later. Sometimes the gateway times out before hand. I want to stress: - This code hasn't been updated in years
- This code has been working for years
- The problems started yesterday morning
- When I isolate the mail send function by itself it sends mail just fine
- When I comment out the send mail function, everything works (other than mail getting sent)
- When I combine the two…problems (even though I probably haven't made a change to this section of the code in at least 2 years.
All things considered, I'm POSITIVE that the issue is not with me but with the mail server. However, /var/log/maillog is empty and of course my hosting company will only do so much in the way of diagnostics. Anybody ever see anything like this before?
|

February 26th, 2013, 09:57 AM
|
|
|
|
Was your MTA changed/updated? When you say the log file is empty do you mean is it 0 bytes or that you didn't see anything pertaining to this problem? If the former, you need to have Postfix logging turned on. There may be errors but they are not being logged.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.
|

February 26th, 2013, 09:58 AM
|
 |
300lb Bench!
|
|
Join Date: Aug 2001
Location: New York
|
|
|
It's 0 bytes. Ok, I'll try and get the logs turned on.
|

February 27th, 2013, 01:57 PM
|
 |
300lb Bench!
|
|
Join Date: Aug 2001
Location: New York
|
|
|
While I wasn't able to turn on logging on the mail server, I was able to produce a working example of what's causing my issue.
Steps are:
1. Do a mysql insert with two fields. One is just an id. The other is a longtext field that will have between 20kb and 40kb of data (serialized object).
2. Send out an email
3. Wait 10 seconds
4. Repeat steps one and two
The second time around the process takes 15-20 seconds to complete. Again, I've been doing this for years. Literally, my database has over 2,000 games like this without a single issue. Any other thoughts?
It almost doesn't seem to be a mail server issue per se. Because when it hangs, I check the mail server. Sometimes it hangs and the data hasn't reached the mail server (I'm watching it). I'm beginning to suspect that it's a *routing* issue. As in, the darn thing is probably struggling to figure out where to route the thing. Although why it would be able to figure it out the first time no problem? I'm stumped at this point.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|