#1
  1. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,353
    Rep Power
    62

    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?
    Correspondence chess
    nothingbutchess.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,604
    Rep Power
    595
    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.
  4. #3
  5. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,353
    Rep Power
    62
    It's 0 bytes. Ok, I'll try and get the logs turned on.
    Correspondence chess
    nothingbutchess.com
  6. #4
  7. 300lb Bench!
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2001
    Location
    New York
    Posts
    2,353
    Rep Power
    62
    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.
    Correspondence chess
    nothingbutchess.com

IMN logo majestic logo threadwatch logo seochat tools logo