PHP Script that sends mail - Postfix breaks it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PHP Script that sends mail - Postfix breaks it
# 1  
Old 03-05-2008
PHP Script that sends mail - Postfix breaks it

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.
Code:
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

2. Linux

Line breaks in mail spool

Hi, I have an issue with the line breaks in the mail spool- /var/mail/user1. I have set up a script to go through the mail spool on one of the users and parse some parts of the mail, however there doesn't seem to exist the regular line endings CR, LF or both in the lines and this is breaking my... (4 Replies)
Discussion started by: night_watcher
4 Replies

3. Homework & Coursework Questions

Creating a function that sends a mail using mail command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: The function will be called m and it will allow you to send an email to someone using the mail command. The... (1 Reply)
Discussion started by: Drucian
1 Replies

4. UNIX for Dummies Questions & Answers

Sending Mail with Postfix

im able to install postfix on my ubuntu server. no issues. but ican't send mail. i dont know what to put for the "relayhost". i've googled this endlessly but i'm clueless. isn't there a general smart host i can use that'll allow me to send? i dont care for receiving mail. i just want to be... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

check postfix deferred mail and send notification script

Hi Guys, I have a postfix server which is deferring emails. Now I need to send notification to a specific email address if: The sender of the deferred email is: abc@example.com Contains specific subjects: a file (/opt/subjects) contains all the subjects in place Then need to send a... (0 Replies)
Discussion started by: linuxrulz
0 Replies

6. Red Hat

Mail solution for Linux - Postfix

Hi , I am a complete newbie to linux, I have been given a job to install a mail solution (postfix if possible) I would like to know how should I go about installing..) Can any one provide me some steps to go about it.. i have read about postfix and the installation steps, it seems there are... (1 Reply)
Discussion started by: anilhk
1 Replies

7. IP Networking

postfix - reinject mail to postfix from hold queue directory

hi all. Am using smtpd_recipient_restrictions & check_recipient_access in postfix. The hash file looks like this: emailaddress1 HOLD emailaddress2 HOLD The aim is to place email from these recipients in the hold directory,check them then reinject them back in postfix on some... (0 Replies)
Discussion started by: coolatt
0 Replies

8. Shell Programming and Scripting

how to know if the mailx command really sends the mail to the email address?

Hi guys, I have a question about the returning message of the mailx command. if I run a mailx command, how can I know if the email has been sent to the email address? If the email address doesn't exist, is there any error message returned? If yes, how can I get the error message? Thanks... (3 Replies)
Discussion started by: sheenshine
3 Replies

9. UNIX for Dummies Questions & Answers

mail command woth Postfix

Hi, maybe someone could help me. This is the thing. I usually use the command "mail" on my scripts to send me info about the linux box, something like: df -k | mail -s "disk usage" lalala@lalala.com. This works fine in all the linuxes that sendmail is installed, but there is one with Postfix... (1 Reply)
Discussion started by: piltrafa
1 Replies

10. UNIX for Dummies Questions & Answers

Cron Sends mail to root on completion of job.

All I am running a few scripts through a cron job. This is for checking some key services that are running on by box. The problem is, everytime the cron runs, it sends a mail to the root account. The root account mails need to cleared every now and then. Is there some way I can stop these... (1 Reply)
Discussion started by: skotapal
1 Replies
Login or Register to Ask a Question