NYCPHP Meetup

NYPHP.org

[nycphp-talk] Emails not being received when using mail()

B.A.S. lists at nopersonal.info
Mon Jan 14 21:24:28 EST 2008


Hans Kaspersetz wrote:
> So my guess is that the address the mail is coming from doesn't exist or 
> the headers are malformed.  Send us the complete headers for on of your 
> generated emails.
> 
> It should look like:
> 
> Subject: foo bar
> From: blah blah <blahblah at cyberxdesigns.com>
> Date: Mon, 14 Jan 2008 19:09:03 -0600
> To: "Blah blah" <blahblah at cyberxdesigns.com>
> Return-path: <blahblah at cyberxdesigns.com>
> Envelope-to: blahblah at cyberxdesigns.com
> Delivery-date: Mon, 14 Jan 2008 20:09:01 -0500
> Received: from [189.149.170.20] (helo=[192.168.0.198]) by 
> host.cxdhosting.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) 
> (envelope-from <blahblah at cyberxdesigns.com>) id 1JEaIR-0006mC-1b for 
> blahblah at cyberxdesigns.com; Mon, 14 Jan 2008 20:08:55 -0500
> Message-ID: <478C07AF.9 at cyberxdesigns.com>
> User-Agent:
> Thunderbird 2.0.0.9 (Windows/20071031)
> 
> 
> That will start to help us pin point what the problem is.
> 
> Hans

Thanks, Hans. Here are the headers:

Return-path: <nobody at mercury.hostspectrum.com>
Envelope-to: recipient3 at example.com
Delivery-date: Mon, 14 Jan 2008 19:49:12 -0600
Received: from nobody by hosting.company.com with local (Exim 4.68)
	(envelope-from <nobody at mercury.hostspectrum.com>)
	id 1JEavQ-0007T3-9u; Mon, 14 Jan 2008 19:49:12 -0600
To: recipient1 at example.com
Subject: Newsletter Request
From: me at example.com
To: recipient2 at example.com
Cc: recipient3 at example.com
Reply-To: me at example.com
Message-Id: <E1JEavQ-0007T3-9u at mercury.hostspectrum.com>
Date: Mon, 14 Jan 2008 19:49:12 -0600

Hmmm, I wonder why "Envelope-to:" is the same as "Cc:" in the headers? 
Anyway, here's my code for creating the headers & sending the mail:

/* code to initialize other variables, validate & filter incoming data, 
etc. */

// initialize variables
$to = 'recipient1 at example.com';
$subject = 'Newsletter Request';

// build message
$message = "\nName: $name\n\n";
$message .= "E-mail: $email\n\n";
$message .= "Received from IP: $ip on $timestamp\n\n";
$message .= "-----------------\n\n";
$message .= "This e-mail was automatically generated by your form 
processing script. The submitted data was also written to a CSV file on 
your server.\n";

// build additional headers
$additionalHeaders = "From: me at example.com\r\n";
$additionalHeaders .= "To: recipient2 at example.com\r\n";
$additionalHeaders .= "Cc: recipient3 at example.com\r\n";
$additionalHeaders .= "Return-Path: -f me at example.com\r\n";
$additionalHeaders .= "Reply-To: me at example.com\r\n";

if (!isset($error)) {
     $mailSent = mail($to, $subject, $message, $additionalHeaders);
    /* code to write to csv file */
}

/* a few more lines of code to handle errors & close script */

Regards,
Bev




More information about the talk mailing list