Jump to content

Php Mail() Function


Iki

Recommended Posts

I've got a custom site working where people fill out a form and an email is sent to them containing a "secret code" using php's mail() function. I was thinking about adding a regex check to see if the email address they entered is valid, but I'm torn. What do I care if the email they entered is valid or not? If it's not, all it means is they won't get the email, and I don't care if they ever get the email. I know the script works on several different emails - charter, gmail, yahoo, other TCH domains. If they can't get their secret code using an AOL account, all I've got to say is get yourself a REAL isp. :D

 

We'll call the domain running this script domain1.

 

Then I started thinking about the server; is something going to come back to the server? The return path and return address are valid - I have domain1 set up so any email sent to domain1 gets forwarded to me. But no matter what I put in the email field on the form, nothing ever comes back to me.

 

I've also got domain2, and that's set up for :fail: if you send to an unrouted address. So earlier I used a non-existent domain2 address on the form, figuring I'd get something at one place or the other, right?

 

I didn't get anything back at either domain1 or domain2.

 

So what I'm wondering is, what happens to undeliverable email using php's mail() script? Does the server take a hit? I'm not seeing anything in my error logs. How do I tell?

Link to comment
Share on other sites

You need to supply a from address in the email so servers know where to return the emails to. At the end put "From: \"Your name\" <you@yoursite.com>\n" and then any bounced emails should go to the address you provided.

Edited by carbonize
Link to comment
Share on other sites

Here's what I've got:

 

>$maili = "postings@pbem2.com";  
$subject = 'Key Code For Your Game Announcement';  
$message = 'blah blah blah';
$message = wordwrap($message, 70);	 
$headers="";	 
$headers .= "X-Sender:  $email <$email>\n"; 
$headers .="From: $maili <$maili>\n";	 
$headers .= "Reply-To: $maili <$maili>\n";	 
$headers .= "Date: ".date("r")."\n";	 
$headers .= "Message-ID: <".date("YmdHis")."postings@".$_SERVER['SERVER_NAME'].">\n";	 
$headers .= "Subject: $subject\n";	 
$headers .= "Return-Path: $maili <$maili>\n";	 
$headers .= "Delivered-to: $maili <$maili>\n";	 
$headers .= "MIME-Version: 1.0\n";	 
$headers .= "Content-type: text/plain;charset=ISO-8859-9\n";	 
$headers .= "X-Priority: 3\n";	 
$headers .= "Importance: Normal\n";	 
$headers .= "X-MSMail-Priority: Normal\n";	 
$headers .= "X-Mailer: My Mailer With PHP!\n";	

mail($email, $subject, $message, $headers);

 

Shouldn't the undeliverable stuff come back to the $maili address? Because it doesn't. :D

Link to comment
Share on other sites

I don't know where yours is, so I sent one to myself. Here's the headers:

 

>Return-Path: <nobody@server98.tchmachines.com>
Received: from mxsf41.cluster1.charter.net ([10.20.201.173])
	  by mtao01.charter.net
	  (InterMail vM.6.01.06.00 201-2131-130-20051209) with ESMTP
	  id <20060530220733.ISMG12200.mtao01.charter.net@mxsf41.cluster1.charter.net>
	  for <myemail@charter.net>; Tue, 30 May 2006 18:07:33 -0400
Received: from mxip02a.cluster1.charter.net (mxip02a.cluster1.charter.net [209.225.28.132])
by mxsf41.cluster1.charter.net (8.12.11/8.12.11) with ESMTP id k4UM7Bpm024035
for <myemail@charter.net>; Tue, 30 May 2006 18:07:31 -0400
Received: from server98.tchmachines.com ([204.11.51.229])
 by mxip02a.cluster1.charter.net with ESMTP; 30 May 2006 18:07:28 -0400
X-IronPort-AV: i="4.05,191,1146456000"; 
  d="scan'208"; a="196301475:sNHT18154656"
Received: from nobody by server98.tchmachines.com with local (Exim 4.52)
id 1FlCN8-0007nO-F8
for myemail@charter.net; Tue, 30 May 2006 18:07:30 -0400
To: myemail@charter.net
Subject: Key Code For Your Game Announcement
X-Sender:  myemail@charter.net <myemail@charter.net>
From: "postings@pbem2.com" <postings@pbem2.com>
Reply-To: "postings@pbem2.com" <postings@pbem2.com>
Date: Tue, 30 May 2006 18:07:30 -0400
Message-ID: <20060530180730postings@www.pbem2.com>
Subject: Key Code For Your Game Announcement
Delivered-to: postings@pbem2.com <postings@pbem2.com>
MIME-Version: 1.0
Content-type: text/plain;charset=ISO-8859-9
X-Priority: 3
Importance: Normal
X-MSMail-Priority: Normal
X-Mailer: My Mailer With PHP!
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - server98.tchmachines.com
X-AntiAbuse: Original Domain - charter.net
X-AntiAbuse: Originator/Caller UID/GID - [99 99] / [47 12]
X-AntiAbuse: Sender Address Domain - server98.tchmachines.com
X-Source: 
X-Source-Args: 
X-Source-Dir:

Edited by Iki
Link to comment
Share on other sites

You're probably right. But my headers aren't putting that in the email; it's being added somewhere along the line. :) I'm specifying the return path right in my headers, but that line never makes it into the actual headers.

 

I just deleted the first header line (the blank one) and put the return path line at the very top and it still doesn't make it into the actual email headers.

 

Oh well. Thanks for trying!

Link to comment
Share on other sites

I can't even remember where I got those headers now. *lol* When I first made this function I was just using the from, subject, to, and message body variables. And still, it botched the return path:

 

>Return-Path: <nobody@server98.tchmachines.com>
Received: from mxsf30.cluster1.charter.net ([10.20.201.230])
	  by mtao02.charter.net
	  (InterMail vM.6.01.05.04 201-2131-123-105-20051025) with ESMTP
	  id <20060427065837.KZGU4189.mtao02.charter.net@mxsf30.cluster1.charter.net>
	  for <myemail@charter.net>; Thu, 27 Apr 2006 02:58:37 -0400
Received: from mxip09a.cluster1.charter.net (mxip09a.cluster1.charter.net [209.225.28.139])
by mxsf30.cluster1.charter.net (8.12.11/8.12.11) with ESMTP id k3R6wILe016444
for <myemail@charter.net>; Thu, 27 Apr 2006 02:58:36 -0400
Received: from server98.tchmachines.com ([204.11.51.229])
 by mxip09a.cluster1.charter.net with ESMTP; 27 Apr 2006 02:58:32 -0400
X-IronPort-AV: i="4.04,160,1144036800"; 
  d="scan'208"; a="60988341:sNHT22002374"
Received: from nobody by server98.tchmachines.com with local (Exim 4.52)
id 1FZ0Sv-0005yh-4k
for myemail@charter.net; Thu, 27 Apr 2006 02:59:05 -0400
To: myemail@charter.net
Subject: Your Game Posting Announcement Number
From: nobody@pbem2.com
Reply-To: nobody@pbem2.com
X-Mailer: PHP/4.4.2
Message-Id: <E1FZ0Sv-0005yh-4k@server98.tchmachines.com>
Date: Thu, 27 Apr 2006 02:59:05 -0400
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
X-AntiAbuse: Primary Hostname - server98.tchmachines.com
X-AntiAbuse: Original Domain - charter.net
X-AntiAbuse: Originator/Caller UID/GID - [99 99] / [47 12]
X-AntiAbuse: Sender Address Domain - server98.tchmachines.com
X-Source: 
X-Source-Args: 
X-Source-Dir:

 

I'd read somewhere that this "nobody" address was a spam trigger, so I went looking for some better headers in an attempt to stop the emails from going into people's spam folders.

 

I'm thinking the "nobody@server98" thing is what happens when the email originates from PHP. You can reply to these emails, and they come back to me like they should. But bounced email must be going into a blackhole. And that's fine with me - I just don't want to wake up one day and find my TCH account suspended because of something to do with this mailer. :)

Link to comment
Share on other sites

Excellent! Jumping off point, anyway. :D

 

My return address was held in the variable $maili so it's:

 

>mail($email, $subject, $message, $headers, "-f $maili"); 

or

mail($email, $subject, $message, $headers, "-f$maili");

 

The space in there doesn't seem to matter, I get this either way.

 

>Return-Path: <postings@pbem2.com>

 

But putting that period in there gives me this in the headers:

 

>Return-Path: <.postings@pbem2.com>

 

If your return address isn't held in a variable, and say it's "return@me.com", you can just put it in there like this:

 

>mail($email, $subject, $message, $headers, "-freturn@me.com");

 

and that works too. Either way, you're definitely going to need those quotes.

 

Oh, have I mentioned this? ... :tchrocks:

 

I fired up this site last night and already have 5 or 6 people who aren't getting the emails... hopefully this will help them. Should have checked in here last night. :rolleyes: (Although I can't help them with their spam filters or software... alas.)

 

Many many thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...