Trying to fix a problem with form mail script - works fine on LINUX but throws this error on a Windows machine:

"Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\hosting\7762152\html\contact.php on line 28"

I understand this has to do with "bare LF's" (line feeds.) Lines being terminated with "\n" when they should be terminated with "\r\n".

My script:

<?php


$to = "info@domain.com";
$from = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"schedule"} = "Schedule";
$fields{"pricing"} = "Pricing";
$fields{"proof"} = "Proof-of-Concept";
$fields{"email"} = "Email Address";
$fields{"phone"} = "Phone Number";

$body = "We have received the following information:\n\n"; 
foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: info@domain.com";
$subject2 = "Thank You For Acme Software";
$autoreply = "Thank you for contacting Acme Software. We will get back to you as soon as possible, usually within 48 hours.";

if($from == '') {print "You have not entered an email address, please go back and try again";}
else {
if($phone == '') {print "You have not entered a phone number, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify info@domain.com"; }
}
}


?> 

So, I am to replace all instances of \n with \r\n, correct? This fix still throws an error.

Can anyone tell me how to fix this?

Thanks!

    Can you show us what you modified to code to in order to attempt this fix?

      Change all instances of \n to \r\n.

      $body = "We have received the following information:\r\n";

      Now it works! I'm no expert but had no idea PHP that runs on LINUX does NOT work on Windows.

      Thanks!

        If coded properly it should be portable, but not all applications are coded to be portable.

          I've not experimented with it, but some people have written that if you use the PHP_EOL constant for all line breaks in mail headers and the message body, you are less likely to have portability problems.

          $headers = 'From: foo@bar.net' . PHP_EOL . 'Reply-To: bar@foo.com';
          $msg = 'This is a test.' . PHP_EOL . PHP_EOL . 'It is only a test.';
          mail($to, $subj, $msg, $headers);
          
            NogDog;10978910 wrote:

            I've not experimented with it, but some people have written that if you use the PHP_EOL constant for all line breaks in mail headers and the message body, you are less likely to have portability problems.

            I would think that is actually going to make you more likely to have portability problems; PHP_EOL varies depending upon which O/S PHP is running on, while the RFC standards for SMTP do not.

              bradgrafelman;10978928 wrote:

              I would think that is actually going to make you more likely to have portability problems; PHP_EOL varies depending upon which O/S PHP is running on, while the RFC standards for SMTP do not.

              Some of the user comments suggest it on the mail page due to the way UNIX sendmail works, but like I said, I've never run into a problem so far with mail() in that regard, so have not tried it.

                Write a Reply...