NYCPHP Meetup

NYPHP.org

[nycphp-talk] bounced email and Mail::send()

Kenneth Downs ken at secdat.com
Sun Oct 23 18:30:09 EDT 2005


I went nuts with this until I gave up on shell emails and used TCP.  The
TCP option requires you to have your email server running, but on the
other hand, the shell method made it impossible to get the Return path
right, and that was a deal-breaker.  Using the PEAR package the code is
this:

// Assume an array $em() that has some stuff in it
include_once('Mail.php');
$recipients =$em["email_to"];
$headers['From']    = $from_name. "<".$from_addr.">";
$headers['To']      = $em["email_to"];
$headers['Subject'] = $em["email_subject"];
$headers['Date']    = date("D, j M Y H:i:s O",time());
$body = $em["email_message"];
$mail_object = Mail::factory('smtp', $params);
$mail_object->send($recipients, $headers, $body);

Once I got this running I've never looked back.

> Thanks, Anirudh.  I'll look into this some more.  To pass the -f flag to
> the PHP mail() function might work, but also I am trying to do this with
> PEAR Mail::send(), so I will dig deeper into that codebase to look for
> clues.
>
> Still mystified,
> Allen
>
> Anirudh Zala wrote:
>> Normally you do not require to set header "Return-path" because return
>> path address is automatically taken by Sendmail as the user who sends
>> emails. Hence in your case it is "apache" when when sending mail from
>> web and "shell user" while sending mail from shell.
>>
>> Hence now you have only 2 options. To set above header in desired way,
>> do not pass "Return-path" header while sending email. Instead in mail
>> function use 5th arguments like below.
>>
>> mail('To mail', 'Subject', 'Message', 'All required header', '-f
>> bounce at someone.some');
>>
>> This fifth parameter (was added in PHP 4.0.5) is your Return-Path. Here
>> "bounce at someone.some" is your bounce mail address. Alternatively you can
>> set permanent address in your php.ini or httpd.conf like below.
>>
>> /usr/sbin/sendmail -f 'bounce at someone.some'
>>
>> Please note that I have not tested above, so you have to try. But it
>> will work most probably or you may have to change syntax according to
>> php.ini or httpd.conf.
>>
>> And sending mail from shell, invoke sendail command by using "-f" option
>> and specify bounced email adress. See below.
>>
>> [...]# /usr/sbin/sendmail -f 'bounce at someone.some' REST OF ARGUMENTS
>>
>> Thanks
>>
>> Anirudh Zala
>>
>> ---------------------------------
>> Anirudh Zala (Production Manager)
>> Ph: +91 281 245 1894
>> anirudh at aspl.in
>> http://www.aspl.in
>> ---------------------------------
>>
>
> --
> Allen Shaw
> Polymer (http://polymerdb.org)
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>


-- 
Kenneth Downs
Secure Data Software
631-379-0010
ken at secdat.com
PO Box 708
East Setauket, NY 11733




More information about the talk mailing list