Categories
PHP

Warning: mail(): SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in path_to_php_file on line #

Full error message: Warning: mail(): SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in path_to_php_file on line #

This is an error message that I got lots of times and it was always the same problem. So I decided to write here the solution for the next time I encounter it and I thought it might also help other people.

So I tried to send an email in plain text using the PHP function mail() :

// consider this being an existing email address
$to_address = "abc@def.com";
$subject = "Email subject";
$message = "line1
line2
line3";
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "To: <".$to_email.">\r\n";
$headers .= "From: Me <".$my_email_address.">\r\n";
mail($to_email, $subject, $message, $headers);

It worked fine with Apache server running on Linux operating system, but I got the error message mentioned before with the server running on Windows.
It looks like while Unix-based systems recognize \n character (the equivalent in PHP of LF – line feed) as a newline even when sending emails, Windows systems are stricter in comunicating using some textual Internet Protocols (such as SMTP) that mandate the line terminator to be the ASCII CR+LF (carriage return + line feed) sequence, which is abstracted in PHP to \r\n character sequence.

So the problem was the $message variable. The correct way to assign the multiple lines value to it is:

$message = "line1\r\nline2\r\nline3";  // separate the lines with \r\n
// or,  elegantly:
$message = "line1\r\n";
$message .= "line2\r\n";
$message .= "line3";

And now it works on Windows, too.

89 replies on “Warning: mail(): SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in path_to_php_file on line #”

@Alex, it seems to me that your script is not saved with Windows line delimiters and this also affects the the heredoc sintax string you pass as the e-mail body. I’m convinced that at least some of the lines in that string are delimited by \n instead of \r\n.
You can check in a PHP editor the file settings of your script to see what line delimiters were used when it was saved, for example in Eclipse you can find this feature under the File menu option: Convert Line Delimiters To (you might like this one to be set to Windows, rather than to Unix or Mac OS).
But you can easily check in PHP weather all the lines in the $body variable are delimited by \r\n by inserting the next lines in your code after assigning to the variable $body that string having the heredoc syntax:
echo "\\n character is ".substr_count($body, "\n")." times in the \$body variable
";
echo "\\r\\n character is ".substr_count($body, "\r\n")." times in the \$body variable
";

If the results of the two calls of the function substr_count() are different, it means that some of the lines are not separated by \r\n and you should fix this either by modifying the $body part of the code like this:
$body = <<<EOD
Email: $email
Name: $name
Message: $message
EOD;
$body = str_replace("\n", "\r\n", $body);

or assigning a single quoted or double quoted string to the variable $body:
$body = "Email: ".$email."\r\n"
."Name: ".$name."\r\n"
."Message: ".$message."\r\n";

or by converting the new line characters used in the script to \r\n using the facilities offered by your PHP editor.

i have get this error
Please help i need this resolved

Warning: mail() [function.mail]: SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in D:\Hosting\6380341\html\scripts\email.php on line 24
Thank you the email!!!!
<?php

$emailSubject = 'email';
$webMaster = 'mhoque@schoolnet.com';

$firstField = $_POST['first];
$lastField = $_POST['last'];
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];

$body = <<<EOD

First: $first
Last: $last
Email: $email
Phone: $phone
EOD;

$headers = “From: $email\r\n”;
$headers .= “Content-type: text/html\r\n”;
$success = mail($webMaster, $emailSubject, $body, $headers);

/* */
$theResults = <<<EOD

Untitled Document

Thank you the email!!!!

EOD;
echo “$theResults”;

?>

OK… I am using Godaddy with IIS 7. I made the changes and I still get the same error. If someone could help I would greatly appreciate it. 🙂
I am using the following code:

//If there is no error, send the email
if(!isset($hasError)) {
$contact_show = false;
$emailTo = $gw_options[‘contact’][‘contact_mail’];
$body = “Name: $name \n\rEmail: $email \n\rSubject: $subject \n\rComments:\n\r $comments”;
$headers = ‘From: My Site ‘ . “\r\n” . ‘Reply-To: ‘ . $email;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;

I had some things turned around. I made the following changes:

//If there is no error, send the email
if(!isset($hasError)) {
$contact_show = false;
$emailTo = $gw_options[‘contact’][‘contact_mail’];
$body = “Name: $name\r\n Email: $email\r\n Subject: $subject\n\r Comments: $comments\r\n”;
$headers = ‘From: My Site ‘ . “\r\n” . ‘Reply-To: ‘ . $email;

mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}

I still get the same type of error but on a different line….

Guys,

i have one doubt,does anyone of you who are using godaddy getting emails late? because i m receiving mails late,not sure whether there is prob with godaddy mail server.

thanks so much for the tip!

for anyone confused, make sure you delete the lines where you have pressed ENTER, those big blank gaps. that is part of why the script breaks.

doing contract work for a client on godaddy windows grid hosting.

If anyone is still watching this thread –

I am using someone else’s code and have been fighting with this for weeks and no matter what I do I continue to get the 451 error. Can someone help me please before I loose my mind?

<?php

/*

* YOUR EMAIL ***

*/

$adminEmail = "inTouch@vanguard-systems.net";

/*

* VALIDATE EMAIL ***

*/

function validateEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

/*

* CHECK FORM ***

*/

$post = (!empty($_POST)) ? true : false;

if($post) {
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = "Get In Touch Web Form Submission";
$message = stripslashes($_POST['message']);
$error = '';

/*

* CHECK MESSAGE ***

*/

if(!$message || $message == "Message") {
$error = "Please, type in a message.";
}

/*

* CHECK MAIL ***

*/

if($email && !validateEmail($email) || $email == "Email") {
$error = "Please, check your e-mail address.";
}

if(!$email || $email == "Email") {
$error = "Please, type in your e-mail address.";
}

/*

* CHECK NAME ***

*/

if(!$name || $name == "Name") {
$error = "Please, type in your name.";
}

/*

* ACTION ***

*/

if(!$error) {
$mail = mail($adminEmail, $subject, $message,
"From: ".$name." \r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
if($mail) {
echo 'ok';
}
} else {
echo ''.$error.'';
}
}

?>

@Tillman, I think the problem is that the lines of the posted strings are separated by \n instead of \r\n. Try

$message = stripslashes($_POST['message']);
$message = str_replace("\n", "\r\n", $message);

Hi im getting this warning when trying my contact form:

Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\5792609\html\contactform.php on line 27

Here is some of the code associated with it:

$emailField = $_Post[’email’];
$nameField = $_Post[‘name’];
$budgetField = $_Post[‘budget’];
$pagesField = $_Post[‘pages’];
$commentsField = $_Post[‘comments’];

$body = <<<EOD
Email: $email
Name: $name
Budget: $budget
Pages: $pages
Comment: $comment
EOD;

$headers = “From: $email\r\n”;
$headers .= “Content-type: text/html\r\n”;
$success = mail($webMaster, $emailSubject, $body,
$headers); <————–THIS IS LINE 27
/* Results as html */

$theResults = <<<EOD

im not sure what to do with it. im not that experienced with php coding. thanks for any help given

That worked perfectly. thanks very much. should have read the page properly the first time!

Thanks again

This post SAVED MY BUTT!! I also chewed out a guy from GoDaddy and, yes, I now feel bad as well. I was getting this error and no matter how much I changed this mail () syntax, I still got nothing.

I’m a total PHP n00b, and this error was my first major obstacle in learning this stuff. I’m so glad I found this, even though I still don’t quite get what /r is. No matter. I’ll learn it in time. Thanks again!!

I’m encountering the above problem with my godaddy form. It was working perfectly until a couple of days ago, and now it returns:

Warning: mail(): SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in path_to_php_file on line 30

Below is the code, I’ve tried replacing the \n with \r\n with no luck. I’d really appreciate if someone could help me out – the programmer that helped me with the site is now long gone.

<?php
$from_email = '-';
$to_email = '-';

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: {$name} \r\n”;
$headers .= “X-Sender: \r\n”;
$headers .= “X-Mailer: PHP ” . phpversion() . “\r\n”;
$headers .= “X-Priority: 3\r\n”;
$headers .= “Return-Path: \r\n”;
$headers .= “Reply-To: “;

$subject = ‘Inquiry from young kim paint website’;
$message = ”
Information Received
Name : $name
Phone Number : $phone
Email : $email
Comment:
$comment
“;

mail($to_email, $subject, trim( $message ), $headers );
?>

alert(“Inquiry Sent”);
location.href=’contact.php’;

Here’s the code (some of it got cut off before)

<?php
$from_email = '—';
$to_email = '—';

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: {$name} \r\n”;
$headers .= “X-Sender: \r\n”;
$headers .= “X-Mailer: PHP ” . phpversion() . “\r\n”;
$headers .= “X-Priority: 3\r\n”;
$headers .= “Return-Path: \r\n”;
$headers .= “Reply-To: “;

$subject = ‘Inquiry from young kim paint website’;
$message = ”
Information Received
Name : $name
Phone Number : $phone
Email : $email
Comment:
$comment
“;

mail($to_email, $subject, trim( $message ), $headers );
?>

alert(“Inquiry Sent”);
location.href=’contact.php’;

@Sam, I don’t see any \r\n in the message body ($message variable), please read the post carefully before asking others to solve your particular problem. Reading other people’s comments might help too.

Hello, While executing the above php code, this error was displaying “Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\7454488\html\test2\contact.php on line 26
We encountered an error sending your mail, please notify admin@unicksolutions.com” . The code in the line 26 was depends to these lines

else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{

The complete PHP code shone below…

$b){ $body .= sprintf(“%20s: %s\n”,$b,$_REQUEST[$a]); }

$headers2 = “From: admin@unicksolutions.com.com“;
$subject2 = “Thank you for contacting us”;
$autoreply = “Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at http://www.unicksolutions.com“;

if($from == ”) {print “You have not entered an email, please go back and try again”;}
else {
if($name == ”) {print “You have not entered a name, please go back and try again”;}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{
header( “Location: http://www.unicksolutions.com/thankyou.html” );}
else
{
print “We encountered an error sending your mail, please notify admin@unicksolutions.com“; }
}
}
?>

sorry above mentioned code is not a complete PHP code…
This was the complete PHP code….

$b){ $body .= sprintf(“%20s: %s\n”,$b,$_REQUEST[$a]); }

$headers2 = “From: admin@unicksolutions.com.com“;
$subject2 = “Thank you for contacting us”;
$autoreply = “Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at http://www.unicksolutions.com“;

if($from == ”) {print “You have not entered an email, please go back and try again”;}
else {
if($name == ”) {print “You have not entered a name, please go back and try again”;}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{
header( “Location: http://www.unicksolutions.com/thankyou.html” );}
else
{
print “We encountered an error sending your mail, please notify admin@unicksolutions.com“; }
}
}
?>

Hello All,
I was reading through this hoping to get an answer to my question but the problem is I know nothing of PHP. All i know is basic HTML and CSS.
I designed a website with a contact form. Then I found a PHP script from somewhere (this was over a year ago) and used that for the contact form. The first website I did a year ago it worked just fine and still works. The second website i did now – it won’t work with exactly the same code, but different email and “echo” message. Both sites are hosted on GoDaddy on Windows server and everything should be the same, but the email and echo message.
Here is the code that works:

<?
$subject="from ".$_GET['fName'];
$subject="from ".$_GET['lName'];
$headers= "From: ".$_GET['email']."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("depaepe@comcast.net", $subject, "

Contact letter

“.$_GET[‘message’].”

” , $headers);
echo (“Your message was sent successfully! Please click ‘back’ to return to Red Feather Studio.”);
?>

//window.close()

And here is the code that does not work:

<?
$subject="from ".$_GET['fName'];
$subject="from ".$_GET['lName'];
$headers= "From: ".$_GET['email']."\n";
$headers.='Content-type: text/html; charset=iso-8859-1';
mail("anton@moxietone.com", $subject, "

Contact letter

“.$_GET[‘message’].”

” , $headers);
echo (“Your message was sent successfully! Please click ‘back’ to return to Moxietone.com.”);
?>

//window.close()

If you need to see the sites… the first one is http://www.redfeatherstudio.com (where it works)

and the second is http://www.moxietone.com (where it does not work.) I temporarily replaced the contact form with another one without PHP but i don’t like it because a user has to have an email program to be able to send a message.

Please help! Again, I don’t understand PHP at all… so explain it like i’m 5.

The error I get on the second website is the 451 error that everyone else seems to get…
Thanks!

@Ant13, just replace “\n” and <Enter> with “\r\n”, so your code should be like this:


<?
$subject="from ".$_GET['lName'];
$headers="From: ".$_GET['email']."\r\n";
$headers.="Content-type: text/html; charset=iso-8859-1";
mail("anton@moxietone.com", $subject, "\r\n\r\nContact letter\r\n\r\n".$_GET['message'], $headers);
echo ("Your message was sent successfully! Please click ‘back’ to return to Moxietone.com.");
?>

here is my code i cant get rid of the error. Please Help!

mail(“email@orthointouch.com”, “Orthointouch”, ”

Name: $Name\r\n

Address: $Address\r\n

City: $City\r\n

State: $State\r\n

Country: $Country\r\n

Phone: $Phone\r\n

Email: $Email\r\n

Comments: $Comments\r\n”, “From: $Email\r\nReply-To: $Email\r\n”);

I have gotten the same error as many of you
“Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in …. on line 39

37 $headers = “From: $email\r\n”;
38 $headers .= “Content-type: text/html\r\n”;
39 $success = mail($webMaster, $emailSubject, $body,$headers);
I have read many of the post but still don’t know how to resolve this issue.
I guess I am a little slow 🙁
PLEASE HELP!

Worked.

else {
echo “Thank You. Your message has been sent to Eyeris TV™.”;
$body = “From: $name_field\r\n E-Mail: $email_field\r\n Phone: $phone_field\r\n Message:\r\n $message”;
mail($to, $subject, $body);
}

@Rachael, did you declare $webMaster and $emailSubject? Take a look at $success? usually i use $to and $subject and don’t use a variable for my mail()

It would be highly appreciated if any one can help me to find out the error.
I am also getting the same error message “Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\8668327\html\result.php on line 17″

And my php code is

And I tried to change $formcontent=”From: $name \n Message: $message”;
TO
$formcontent=”From: $name \r\n Message: $message”;

but it is showing “Warning: mail() [function.mail]: SMTP server response: 554 mail server permanently rejected message (#5.3.0) in D:\Hosting\8668327\html\result.php on line 17”

The site is hosted in godaddy. Please help me to sort it out………. Please……..

Why can’t I post my php code here?
sorry for posting it again and again if you can see the code..

help
the script writer cannot help me…
i know nothing about php and i have tried the \r\n as i understand it and still 451 as well 554

thanks for your time

{
$char = array(‘.’,’@’);
$repl = array(‘.’,’@’);
$email=str_replace($repl,$char,$email);
$message = “$lang[t42]\n\n”;
$message.= “$lang[t43]\n\n”;
$message.= “$lang[t17] $name\n”;
$message.= “$lang[t18] $from\n”;
$message.= “$lang[t20] $email\n”;
$message.= “$lang[t19] $url\n”;
$message.= “$lang[t44]\n”;
$message.= “$comments_nosmileys\n\n”;
$message.= “$lang[t45]\n”;
$message.= “$settings[gbook_url]\n\n”;
$message.= “$lang[t46]\n”;

mail($settings[‘admin_email’],$lang[‘t41’],$message,”From: $name \nReply-to: $email\nReturn-path: $email\nContent-type: text/plain; charset=”.$lang[‘enc’]);
}

Hallo,

ich habe the same problem with godday , could you please help me.
this is the php code
$b){ $body .= sprintf(“%20s: %s\n”,$b,$_REQUEST[$a]); }

$headers2 = “From: info@mysite.com“;
$subject2 = “Thank you for contacting us”;
$autoreply = “Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at http://www.mysite.com“;

if($from == ”) {print “You have not entered an email, please go back and try again”;}
else {
if($name == ”) {print “You have not entered a name, please go back and try again”;}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{print( “Thank you” );}
else
{print “We encountered an error sending your mail, please Call us”; }
}
}

?>

thank you in advance

Comments are closed.