View Full Version : returned php-generated mail
pdstein
02-07-2000, 11:35 AM
I have a "recommend this site to a friend" function I wrote in PHP for my website.[nbsp][nbsp]It works great except when people type in a bad email address.[nbsp][nbsp]Even though I have the sender type in their own email address and I include that in both the from and reply-to fields, the "cannot be delivered" response is always sent to PHP3@steinbrueck.org.
Is there a way to make it so the "cannot be delivered" email is sent to the address of the person who actually initiated the email?
- Paul
pdstein
02-07-2000, 02:23 PM
Justin, thanks for the help, but I'm afraid it doesn't work.[nbsp][nbsp]I have:
mail($toEmail, "Recommended Website", $bodySend, "From: $fromEmail \nReply-To: $fromEmail \nReturn-Path: $fromEmail");
and it still sends the "failure notice" email to PHP3@steinbrueck.org[nbsp][nbsp]It seems like even though I try to set the Return-Path field the PHP mail function overrides it.
- Paul
Charles Capps
02-07-2000, 03:27 PM
Try adding \nErrors-To: $fromEmail after Reply-To...
pdstein
02-07-2000, 04:40 PM
That didn't work either.
Justin
02-07-2000, 04:48 PM
Hm, maybe if you wrote the return address in the upper left-hand.... um...
I know I had this working at one time with PHP and using the Return-Path header... I always enclose the email address in <>, though that shouldn't make a difference... One thing I have found to be a pain when using PHP mail - if you use \n as your line terminators (eg, Unix), you must also use \n in the headers - however, if you use \r\n (CRLF, Windows) you must use \r\n to separate headers as well - I think PHP adds the \r's if they are not present, but if one is in the body of the email (eg, submitted by a form from a Windows box) it will not add them to the header...
Ok - long story short - try doing the same thing, with the Return-Path, using "\r\n" instead of just "\n"... :)
Hope this helps.
------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support
pdstein
02-07-2000, 05:13 PM
Thanks again for the suggestion, but no dice.[nbsp][nbsp]I tried \r\n and inclosing the address in <> and neither helped.
This is what is strange.[nbsp][nbsp]I sent the recommendation to myself and looked at the full header.[nbsp][nbsp]All of the fields - To, From, Reply-To, Errors-To, Subject - are all set as instructed in my mail() fn call, but Return-Path is[nbsp][nbsp]<PHP3@steinbrueck.org> no matter what I do.
Justin
02-08-2000, 01:50 AM
</font><font face="Courier" size="3">
mail (
[nbsp][nbsp] "To Whom <to@whom.net>",
[nbsp][nbsp] "Subject: blah",
[nbsp][nbsp] "Thanks for filling out our form!",
[nbsp][nbsp] "From: Me <me@mydomain.com>\nReply-To: Me <me@mydomain.com>\nReturn-Path: Bounces <bounces@mydomain.com>"
);
</font><font face="Verdana, Arial" size="2">
Hope this helps :)
------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support
If you leave out the reply to, where do bad emails go ?
pdstein
02-09-2000, 12:59 PM
Dean, it's not the Reply-To: field that matters it's the Return-Path: field.[nbsp][nbsp]It seems to me that whether you set it or not it is automatically set by PHP to PHP3@rootdomain.com.[nbsp][nbsp]I'm trying to figure out how to change that but haven't been able to so far.[nbsp][nbsp]Unless somee else here can figure it out, my next step is to go to the PHP3 mailing list.
- Paul
Fortune
02-09-2000, 05:45 PM
I had this problem with perl a few months ago and could not solve it.
I think Return-Path is set by FutureQuest.
if so, maybe Terra can answer this.
The reason for my question is that I have the opposite problem.[nbsp][nbsp]I do not ever get bad mail returned to me. I have no idea where they go.
I didn't want to bog down your question or original thread but I will state what is happening to me and why this thread was of interest.
I used to use a CGI mailing list program for my news letter. After every submission of a weekly newsletter I could count on 3-5 bad emails as folks left jobs or ISPs and their e-mail addy went away.
I rewrote this program in PHP and store the mailing list in a mySQL database.[nbsp][nbsp]Now when I send a newsletter I do NOT ever get returned mail.[nbsp][nbsp]Just for 'fun' I typed in a bad e-mail address for a non-exsistant domain. I did not get a single returned mail.
I tried using the suggestions from this thread but I never ever get a returned mail.
Dean
pdstein
02-09-2000, 11:48 PM
Dean, it seems to me that we don't have any control over where the returned mail goes.[nbsp][nbsp]I'm guessing that since my php-generated email is always returned to PHP3@my_domain_name.com that yours is as well.[nbsp][nbsp]You probably don't have a POP mailbox specifically set for PHP3@your_domain_name.com so that would mean it probably ends up in your default mailbox which I think is xusername-username@your_domain_name.com[nbsp][nbsp]Have you checked this recently to see if there is anything in there?
- Paul
Justin
02-10-2000, 12:46 AM
A while back, the default From: address was (I think) PHP3@server.futurequest.net - and I know TeRRa did something to make it PHP3@yourdomain.com - and it just occurred to me that the inability to set the Return-Path may have been a side affect... though I am not sure...
Either way, PDStein is correct *if* you have your catch-all box enabled (or a POP account set up as "PHP3") - if not, you would not receive the bounces at all (because they would themselves bounce and end up going nowhere)...
------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support
It looks as though the default sendmail_path enviroment variable for our php install is:
/usr/lib/sendmail -t -fPHP3@pro-am-electronics.com
(replace pro-am-electronics.com with your domain name)
Put the following in the .htaccess file for the directory containing your script:
php3_sendmail_path /usr/lib/sendmail
Then give it another shot, but be sure to include your Errors-To: in the header, other wise I think root@localhost will wind up with the bounced mail.
I tried to add some command line switches to the sendmail path in the .htaccess file to override the ini settings, but php wouldn't let me do it.[nbsp][nbsp]Here's what it told me:
[Thu Feb 10 01:49:49 2000] [alert] [client 24.93.XX.XX] blah/blah/test/.htaccess: php3_sendmail_path takes one argument, Full path to sendmail binary
Hope that helps.
John
[This message has been edited by JVC (edited 02-10-00@02:07 am)]
Squirrley5
02-11-2000, 07:28 PM
An alternative approach would be to give your users an error if the email address is invalid. I have found a good class for email validation on the PHP Class Repository. You can visit http://phpclasses.upperdesign.com/browse.html/package/13 to view this class, or download it. Hope this helps... =)
pdstein
02-12-2000, 10:44 AM
That will catch some bad email addresses, but it won't catch those where the address is in the right format whatever@server.ext but have the account is cancelled, disabled, misspelled, or otherwise undeliverable.
- Paul
Hmm... real time email address verification.[nbsp][nbsp]Interesting, let me take a crack at it:
function verify_email($email) {
[nbsp][nbsp][nbsp][nbsp] $addr_parts = explode("@", $email);[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* Need error checking */
[nbsp][nbsp][nbsp][nbsp] $user = $addr_parts[0];[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* User name */
[nbsp][nbsp][nbsp][nbsp] $rhostname = $addr_parts[1];[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] /* Remote host */
[nbsp][nbsp][nbsp][nbsp] $lhostname = "localhost";[nbsp][nbsp][nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp] /* Get the name of the mail host from the DNS MX records */
[nbsp][nbsp][nbsp][nbsp] $mx = getmxrr($rhostname, $mxhosts);[nbsp][nbsp][nbsp][nbsp]
[nbsp][nbsp][nbsp][nbsp] $connection = pfsockopen($mxhosts[0], 25, &$errno, &$errstr, 10);
[nbsp][nbsp][nbsp][nbsp] if (!$connection) {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]echo "$errstr ($errno)
\n";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]fclose($connection);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]echo $mxhosts[0];
[nbsp][nbsp][nbsp][nbsp] } else {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* Commands are from RFC 821 */
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$x= "HELO $lhostname\r\n";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$x.= "VRFY $user\r\n";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$x.= "QUIT\r\n";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]fputs($connection, $x);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$c = 0;
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]while (!feof($connection)) {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$buffer[$c] = fgets($connection, 4096);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$c++;
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]fclose($connection);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* Line 4 of response will give us what we're after on Microsoft servers */
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* Should be line 3 on everything else. */
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]$server_response = explode (" ", $buffer[0]);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]if ($server_response[1] == "Microsoft" or $server_response[2] == "Microsoft") {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] $response = explode(" ", $buffer[3]);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]} else {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] $response = explode(" ", $buffer[2]);
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]/* 250 is a good username, 550 is user unknown */
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]if ($response[0] == "250") {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] echo "
$email is a good address";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]} else {
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] echo "
$email is not a valid address";
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]}
[nbsp][nbsp][nbsp][nbsp] }
}
Yep, works for me, your milage may vary.[nbsp][nbsp]Some servers automatically respond 550 user unknown to VRFY queries I think.[nbsp][nbsp]Maybe someone with a little more experience with SMTP servers can shed some light on this. It needs some more error handling and the ability to query more than one MX host should the first fail...
Use <?php verify_email("bubba@over-yonder.com") ?> :)
It's a start at least...
John
Oops, forgot about the Microsoft factor... Should be ok (better) now.
[This message has been edited by JVC (edited 02-16-00@12:41 pm)]
I just noticed the response that Terra's mail server gives:
VRFY john
252 send some mail, i'll try my best
:)
Pretty funny.
Aw well, back to the drawing board...
John
Terra
02-16-2000, 05:13 AM
Wow, I can't believe I totally blitzed this thread... :(
[Thu Feb 10 01:49:49 2000] [alert] [client 24.93.XX.XX] blah/blah/test/.htaccess: php3_sendmail_path takes one argument, Full path to sendmail binary
You were close, very close![nbsp][nbsp];)
You should be able to '.htaccess' override that value...
Try:
php3_sendmail_path "/usr/lib/sendmail -t -fwhereever@yourdomain.com"
The quoting should turn it into 1 argument... :)
--
Terra
--The universe just expanded, and I didn't even notice--
FutureQuest
Fortune
03-08-2000, 04:06 AM
You should be able to '.htaccess' override that value...
Try:
php3_sendmail_path "/usr/lib/sendmail -t -fwhereever@yourdomain.com"
I want to change the default Return-Path: webmaster@mydomain.com in my perl program.
Is there a similar way to do this? Thanks.
[This message has been edited by Fortune (edited 03-08-00@03:09 am)]
pdstein
03-09-2000, 10:46 AM
You should be able to '.htaccess' override that value...
Try:
php3_sendmail_path "/usr/lib/sendmail -t -fwhereever@yourdomain.com"
Since I would have to set a static .htaccess file to set the Return-Path: to the address I want, I am concluding that there is no way to set this on the fly - set the Return-Path: differently for each individual email sent.
Actually, I think you can set just about anything in the header of an email you want.
Here's a snippet that I use:
<?php
$subject = "A response was received from ".$b_firstname ." ". $b_lastname;
$to = "me@somewhere.com";
$message = "\n\nTesting out my email handler...\n\n";
mail($to, $subject, $message,
"From: Your Website <website@somewhere.com>
Reply-To: $b_firstname $b_lastname <$email>
Return-Path: oops@somewhere.com
X-Priority: 2 (High)
X-Mailer: My fancy PHP email generator");
?>
Just don't forget that you need a new line '\n' after each header line.
Hope that clears things up a bit...
J
pdstein
03-10-2000, 12:04 AM
Check out the earlier posts in this thread.[nbsp][nbsp]The solution you suggested has been tried but doesn't work because PHP overrides the Return-Path: setting.[nbsp][nbsp]You can set every other header field this way, but not Return-Path:
Oops sorry, I didn't check this before I posted it.[nbsp][nbsp]I forgot that Terra upgraded us to php 3.0.15.[nbsp][nbsp]I just checked out what I posted and no, it doesn't work now.
The above snippet will work if your path to sendmail directive does not have the -f argument.
From the sendmail man page:
-f sender
Set[nbsp][nbsp]the[nbsp][nbsp]envelope[nbsp][nbsp]sender[nbsp][nbsp]address.[nbsp][nbsp]This[nbsp][nbsp]is[nbsp][nbsp]the address where delivery problems are sent to, unless the message contains an Errors-To: message[nbsp][nbsp]header.
I guess we're not allowed to change the php3_sendmail_path in the .htaccess file since the upgrade to 3.0.15.[nbsp][nbsp]When we were using 3.0.12 I could manipulate these settings and override the php_sendmail_path to NOT include the -f sendmail parameter.
I suppose this is the best way to handle bounced email from an administrator's point of view.
Justin
03-11-2000, 12:47 AM
I wasn't aware that the .15 upgrade caused problems in that area - but i know that before, way back with 3.0.7, bounces were going to webmaster@taz.futurequest.net and similar addresses, thus making the -f option necessary...
------------------
Justin Nelson
FutureQuest (http://www.FutureQuest.net/index.php) Support
Graham
03-17-2000, 01:51 AM
s
struction
09-16-2001, 08:17 PM
Originally posted by pdstein:
Since I would have to set a static .htaccess file to set the Return-Path: to the address I want, I am concluding that there is no way to set this on the fly - set the Return-Path: differently for each individual email sent.
Help!
SInce you've upgraded to PHP4, the syntax for this directive no longer works.
I tried:
php_value sendmail_path "/usr/lib/sendmail..."
to no avail.
Can you help?
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.