note 107558 added to function.mail
| From: | akger1379 at gmail dot com | Date: | Fri, 17 Feb 2012 11:14:27 +0000 |
| Subject: | note 107558 added to function.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186188@lists.php.net to get a copy of this message | ||
* Solution for using mail()/sendmail to send in background mode *
<?php
$additionalParameters = '-ODeliveryMode\=b';
mail($to, $subject, $message, $headers, $additionalParameters);
?>
* More details *
Let's assume you want to send mails in your php script. Normally calling the mail() function
will pause the php script until the mail transfer agent (which is sendmail in most cases) delivered
the mail. Actually this behavior may end up in a quite long timeout, e.g. if the destination server
is not reachable or the internet connection of the server where sendmail is running is not working
properly.
If you search the internet you will find some advices to prevent this behavoir by passing an
argument to sendmail which will force the mail transfer agent to run in background mode. Just look
at this note: http://www.php.net/manual/en/function.mail.php#104054
I tested this solution but had no success. Sendmail was still working in the normal foreground
mode...
So what will be a working solution? At first let's assume we want to call sendmail from the
command line and change it's delivery mode to background. The right sytax for doing so would
be:
sendmail -i -t -ODeliveryMode=b
Notice that there is NO SPACE between the '-O' and the option name
'DeliveryMode'. Ok. Now let's use this option in our php mail function:
<?php
$additionalParameters = '-ODeliveryMode=b';
mail($to, $subject, $message, $headers, $additionalParameters);
?>
Fine, this should normally work. But it won't... I don't know if this is actually a bug
but I still post it here for all the other users running into the same problem. What happend? If you
take a closer look at the running processes and their command line options when php is calling
sendmail you will see something like this:
pstree -a
...
php-cgi
|
| - sh -c /usr/sbin/sendmail -t -i -ODeliveryMode=b
|
| - sendmail -t -i -ODeliveryMode b
Notice the missing '=' between the option and it's value. So sendmail will not parse
this option because of the missing equal sign.
Solution: Escape the '=' with a backslash '\'. I think php should take care of
this. But I'm not sure. Maybe someone could give me a hint to post this as a bugfix or not.
Take care
André
----
Server IP: 69.147.83.197
Probable Submitter: 79.241.206.92
----
Manual Page -- http://www.php.net/manual/en/function.mail.php
Edit -- https://master.php.net/note/edit/107558
Del: integrated -- https://master.php.net/note/delete/107558/integrated
Del: useless -- https://master.php.net/note/delete/107558/useless
Del: bad code -- https://master.php.net/note/delete/107558/bad+code
Del: spam -- https://master.php.net/note/delete/107558/spam
Del: non-english -- https://master.php.net/note/delete/107558/non-english
Del: in docs -- https://master.php.net/note/delete/107558/in+docs
Del: other reasons-- https://master.php.net/note/delete/107558
Reject -- https://master.php.net/note/reject/107558
Search -- https://master.php.net/manage/user-notes.php