[nycphp-talk] sending email from PHP
DeWitt, Michael
mjdewitt at alexcommgrp.com
Fri Jun 11 09:26:46 EDT 2004
In this post I neglected to mention the need to change php.ini so that the
sendmail parameters can be passed. Here is the updated post.
Mike
--------------------------------------------------------------------------
I have some issues along these lines but made a few changes in the way PHP
interfaces with sendmail. Here are the key changes:
1. Set the from address in sendmail before you use it and set delivery mode
to defer. Make sure your from address is a trusted user of sendmail to
suppress the warning of identity change.
$fromaddress='info at yourdomain.com'
putenv("PHP_SENDMAILPARAMS= -O DeliveryMode=defer -f
$fromaddress");
Change the sendmail_path line in php.ini to read:
sendmail_path = /usr/lib/sendmail -t -i $PHP_SENDMAILPARAMS
2. Build your lists and use the regular ole mail command
$datasent=mail($toaddress, $subject,
$bodytext, "From: ".$fromaddress."\r\n"
."Bcc:".$addbcc."\r\n"
."Reply-To: ".$fromaddress."\r\n"
."Errors-To: <".$fromaddress.">"."\r\n"
."X-Mailer: PHP/" . phpversion());
3.Flush the queue or just wait for sendmail's natural queue flush (depends
on how you have this setup and how quickly you need to process the queue)
$processq=exec('/usr/lib/sendmail -q >/dev/null &');
Making these changes made email broadcasts practical and is 100 x faster
than the default setup where php waits for sendmail to deliver.
Hope this helps
Mike
> -----Original Message-----
> From: corey szopinski [SMTP:corey at domanistudios.com]
> Sent: Thursday, June 03, 2004 1:20 PM
> To: NYPHP Talk
> Subject: [nycphp-talk] sending email from PHP
>
> I'm trying to build a tool to send dynamic emails (think order summary)
> from PHP. I'm running into very long delays waiting for sendmail to return
> a result.
>
> For example, a person submits an order, the function that handles the
> transaction does a couple of things:
>
> 1. Sends an order confirmation to the store
> 2. Sends an order confirmation to the customer
>
> The whole process can take over 1 minute, which times out the browser.
> I've tracked it down the delay to sendmail verifying the remote email
> address. Since sendmail talks to the remote mail server in real-time, any
> network lag, or DNS lag, causes the order process to hang. In my case, it
> does it twice.
>
> I've looked at Pear Mail_Queue, and that looks interesting, but a bit
> overkill. I've also looked at going around the mail() function and opening
> an SMTP socket directly to sendmail (same delays... in fact when I open a
> session via command line, I can see the exact step in the SMTP conversion
> where the lag happens)
>
> Here's what I'd like to do (and this would be helpful for anyone sending
> out a modest volume of email)...
>
> 1. send the mail to sendmail
> 2. sendmail puts it into a queue
> 3. sendmail periodically checks this queue and sends the email.
>
> Essentially, I'd like to fork the slow lookup stuff to the background,
> returning control the browser as soon as possible. This has the added
> benefit of scaling to very large emails/hour since the browser never has
> to wait for sendmail (or an external server) before a visitor can move on.
>
> I'm pretty sure that this is intrinsic to the way sendmail works, but most
> of the documentation talks about the queue holding mail that's not
> deliverable. What I'd like to do is put to put a delay on the email before
> it's processed by sendmail.
>
> Any ideas?
>
> -corey
>
>
>
>
> DOMANI STUDIOS
>
> Corey Szopinski
> Technology Director
>
> corey at domanistudios.com
> 70 Washington St. Suite 710
> Brooklyn, NY 11201
> 718.797.4470 x116
>
> << File: ATT13382.txt >>
More information about the talk
mailing list