me_here
me_here

Reputation:

Delay when using PHP mail() function to send email through Exchange (using sendmail as a relay)

I'm using the PHP mail() function to send emails from a Linux server, but using Exchange as the main MTA. To achieve this sendmail has been set up to relay everything to the local Exchange server, which then sends the emails out.

This is working correctly, but the PHP script seems to wait until the timeout limit before finishing. I thought perhaps it's waiting for a response from sendmail, which doesn't come becomes it's just a relay?

I specified the php.ini command line option for "sendmail_path" -odb, which should start sendmail with the "background" delivery mode, meaning to fire off emails in a separate process and then immediately return. But it still takes 30 seconds for the PHP script to end.

Anyone have any ideas? I'm a bit stumped. Thanks.

Upvotes: 3

Views: 9178

Answers (6)

user10306
user10306

Reputation: 1113

An indirect solution.

What we do is use php's system() to send emails in the background so the user doesnt have to wait for the email to go out.

something like this...

<?php //sendEmail.php
mail($argv[1], $argv[2], $argv[3]);
?>

your script:

<?php
...
system("php sendEmail.php [email protected] 'subject' 'message' 1>/dev/null 2>&1 &");
...
?>

Upvotes: 2

Chris Pratt
Chris Pratt

Reputation: 239290

I had a similar question. In my case, the infrastructure team had actually added a 30 second artificial delay. I think it's actually more like a setting to wait for confirmation that the email has actually been sent that by default waits 30 seconds than someone explicitly setting a 30 second delay arbitrarily. Regardless, sounds like you're in the same boat. Check with whoever manages the Exchange server, tell them what's happening, and see if they can spot the setting. In my case, I had to actually log what was happening with Wireshark before I convinced the team that there was actually a problem with Exchange and not my application.

Upvotes: 0

PAT
PAT

Reputation: 507

-odb was deprecated (sendmail version 8.7 onwards). 1
Consider using -ODeliveryMode=b (for the sendmail command line or sendmail_path setting)
Or add O DeliveryMode=b in the additional parameters of the PHP mail function. 2

Upvotes: 1

pablasso
pablasso

Reputation: 2499

Can't say much without looking at the php/mail logs. But why don't you send from PHP directly to your MTA of choice? just use a library like PHPMailer and the authentication will be easy.

Also for debugging purposes you could install postfix (on linux with a package manager takes 3 seconds) and set it up as relay, Postfix logs are pretty extensive on verbose mode and you could discover if sendmail was your bottleneck.

Upvotes: 1

Chris Kloberdanz
Chris Kloberdanz

Reputation: 4536

An alternative might be to use PEAR's Mail. I have used it to send emails to qmail and Exchange SMTP servers.

Upvotes: 0

Neel
Neel

Reputation: 854

If it's any help my sendmail_path looks like this:

sendmail_path = /usr/sbin/sendmail -t -i

Upvotes: -1

Related Questions