PDA

View Full Version : mail() Help


rfresh
03-21-2008, 07:28 PM
My script is sending out an email using mail().

I'm having trouble getting my desired From: address to display when the message is received. The server 'envelope sender address' is being used instead of what i am specifying in my mail() function.

The problem has to do with the fact I'm sending an attachment.

When I email a plain text msg (no attachment) I use this syntax and the -f switch over rides the envelope sender address and forces the use of the From address - and it works just fine:

mail($php_To, $php_Subject, $php_Message, null, '-fjpg@website.com');

This "forces" the from address and shows from jpg@website.com just fine.

However, when I try to send an attachment, it doesn't work the same way because I have to add additional needed attachment header code:

$hdr = "From: jpg@website.com\n";
$hdr .= "MIME-Version: 1.0\n";
$hdr .= "Content-Type: multipart/mixed;";
$hdr .= "boundary=".$boundary."\n";
$hdr .= "Content-Transfer-Encoding: 7bit\n";


And then the server envelope sender address gets used instead of what I am specifiying in the mail() from argument.

I've tried using "From: -fjpg@website.com\n" but it doesn't work.

Does anyone know how I can use this header structure above and still force the from address to over ride the envelope sender address?

rfresh
03-21-2008, 09:27 PM
I found the answer:

$hdr = "From: jpg@website.com\n";
$hdr .= "MIME-Version: 1.0\n";
$hdr .= "Content-Type: multipart/mixed;";
$hdr .= "boundary=".$boundary."\n";
$hdr .= "Content-Transfer-Encoding: 7bit\n";

Drop the first header line above, like this:

$hdr = "MIME-Version: 1.0\n";
$hdr .= "Content-Type: multipart/mixed;";
$hdr .= "boundary=".$boundary."\n";
$hdr .= "Content-Transfer-Encoding: 7bit\n";

And then use the mail() function like this:

mail($php_To, $php_Subject, $msg, $hdr, '-fjpg@website.com');

Works perfect!