I have a PHP Script that works perfectly on a server that uses Sendmail. However I tried to port it to a new server that has the Postfix to Sendmail compatibility interface, and it doesn't work properly.
The php.ini file has the path for sendmail on both servers set to: /usr/sbin/sendmail -t -i
Here is the PHP function.
function send_email($from, $to, $subject, $textMsg, $htmlMsg = ''){
$from = stripslashes($from);
$subject = stripslashes($subject);
$textMsg = stripslashes($textMsg);
if (eregi("\r",$from) || eregi("\n",$from)){
die("Sorry, the from addess is invalid. If you feel you have gotten this message in error, please contact the system administrator.");
}
if (eregi("\r",$to) || eregi("\n",$to)){
die("Sorry, the to addess is invalid. If you feel you have gotten this message in error, please contact the system administrator.");
}
if (eregi("\r",$subject) || eregi("\n",$subject)){
die("Sorry, the subject is invalid. If you feel you have gotten this message in error, please contact the system administrator.");
}
if($htmlMsg > ''){
$body = "\r\n--gc0p4Jq0M2Yt08j34c0p\r\n" .
"Content-Type: text/plain; charset=us-ascii; format=flowed\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
"$textMsg\r\n\r\n" .
"--gc0p4Jq0M2Yt08j34c0p\r\n" .
"Content-Type: text/html; charset=us-ascii;\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
"$htmlMsg\r\n";
}else{
$body = "\r\n--gc0p4Jq0M2Yt08j34c0p\r\n" .
"Content-Type: text/plain; charset=us-ascii; format=flowed\r\n" .
"Content-Transfer-Encoding: 7bit\r\n\r\n" .
"$textMsg\r\n\r\n";
}
$hdr = "Mime-Version: 1.0\r\n" .
"From: $from\r\n" .
"Reply-To: $from\r\n" .
"Content-Type: multipart/alternative; boundary=\"gc0p4Jq0M2Yt08j34c0p\"\r\n" .
"Date: " . date('r') . "\r\n";
mail($to, $subject, $body, $hdr) ;
}
Everything gets shifted or something in the email went it is sent off the Postfix server. The from address becomes blank when I receive it. Then the body looks something like this:
From: jeff@emailhere1.com
Reply-To: jeff@emailhere1.com
Content-Type: multipart/alternative; boundary="gc0p4Jq0M2Yt08j34c0p"
Date: Tue, 04 Mar 2008 21:37:21 -0500
Message-Id: <20080305023721.169903A415D@serverhostname.com>
X-Spam: [F=0.6145044964; B=0.500(0); CM=0.500; MH=0.500(2008030474); R=0.600(10824171516); S=0.515(2008012801); SS=0.500; SC=none]
X-MAIL-FROM: <apache@serverhostname.com>
X-SOURCE-IP: [99.999.999.999]
X-AnalysisOut: [v=1.0 c=0 a=PJwPNPI7AAAA:8 a=5tm0iYomoMYUE1dKbXIA:9 a=ZnIH]
X-AnalysisOut: [FGK1kxZMqYugtdp_urtXkEMA:4 a=TZyYahp_f9YA:10 a=YH6K3Mh3ZBA]
X-AnalysisOut: [A:10]
Return-Path: apache@serverhostname.com
X-OriginalArrivalTime: 05 Mar 2008 02:37:21.0739 (UTC) FILETIME=[D69DC9B0:01C87E69]
--gc0p4Jq0M2Yt08j34c0p
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
email body is here