PHP mail problem

I am trying to get a mail program to work through GoDaddy.  I have another one that does work but I want this one because it looks better with the jquery.  Here is the error


Warning: mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html

Any help is appreciated - it bombs on
mail($emailTo, $subject, $body, $headers);
//If there is no error, send the email
	if(!isset($hasError)) {
		$emailTo = 'joedoe@hotmail.com'; //Put your own email address here
		$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
		$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
		mail($emailTo, $subject, $body, $headers);
		$emailSent = true;

Open in new window

JohnMac328Asked:
Who is Participating?
 
liveaspankajConnect With a Mentor Commented:
Try this one. It will work.

 
if(!isset($hasError)) {
		$emailTo = 'joedoe@hotmail.com'; //Put your own email address here
		$body = "Name: $name \r\n\r\nEmail: $email \r\n\r\nSubject: $subject \r\n\r\nComments:\r\n $comments";
		$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
		mail($emailTo, $subject, $body, $headers);
		$emailSent = true;

Open in new window



or this:

 
if(!isset($hasError)) {
		$emailTo = 'joedoe@hotmail.com'; //Put your own email address here
		$body = "Name: $name, Email: $email, Subject: $subject, Comments: $comments";
		$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
		mail($emailTo, $subject, $body, $headers);
		$emailSent = true;

Open in new window

0
 
stergiumCommented:
try loosing the replyto in the headers  like this
$headers = 'From: My Site <'.$emailTo.'>' . "\n";
and
$emailSent=mail($emailTo, $subject, $body, $headers); //true/false

have you checked your php settings on smtp?
0
 
Chris HarteThaumaturgeCommented:
A bit of searching shows that some other people have had this problem, mainly on the windows rather than the linux server. The line feed character (\n) on its own is not enough, you also need the carriage return character (\r).

They fixed it by replacing all \n with \r\n.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JohnMac328Author Commented:
I am getting the same error on these two lines

      mail($emailTo, $subject, $body, $headers);
            $emailSent=mail($emailTo, $subject, $body, $headers); //true/false
      }
What would I look for under the php settings on smtp through Godaddy?
//If there is no error, send the email
	if(!isset($hasError)) {
		$emailTo = 'johnmac328@hotmail.com'; //Put your own email address here
		$body = "Name: $name \r\n\nEmail: $email \r\n\nSubject: $subject \r\n\nComments:\n $comments";
		$headers = 'From: My Site <'.$emailTo.'>' . "r\n";
		mail($emailTo, $subject, $body, $headers);
		$emailSent=mail($emailTo, $subject, $body, $headers); //true/false 
	}

Open in new window

0
 
Chris HarteThaumaturgeCommented:
You missed one after $subject and before $comments
0
 
JohnMac328Author Commented:
Same error after I changed it
0
 
JohnMac328Author Commented:
This is the old script that has no problems

//send email
$to = "joe@hotmail.com,rick@ricksweb.net";
$subject = "Contact for ".$_SERVER['HTTP_HOST']."";
$body = "on ".date('M j, Y')." Information from contact form: Name: $name With the email address of $email Wrote this message: $message";
$additionalheaders = "From: <joe@hotmail.com> ";
$additionalheaders .= "Replt-To: joe@gvtc.com";
if(mail($to, $subject, $body, $additionalheaders))

Open in new window

0
 
Ray PaseurCommented:
Not this:

$headers = 'From: My Site <'.$emailTo.'>' . "r\n";

But this:

$headers = 'From: My Site <'.$emailTo.'>' . "\r\n";
0
 
Ray PaseurCommented:
This is worth reading:
http://cr.yp.to/docs/smtplf.html
0
 
re-searcherConnect With a Mentor Commented:
I using following code and work on websites which i developing.
I customize it for you. Hope it's be useful for you.
$to = 'joe@hotmail.com'; //rick@ricksweb.net
$subject = 'Contact for '.$_SERVER['HTTP_HOST'];

$headers = 'From: joe@hotmail.com';
$date = date ("l, F jS, Y"); 
$time = date ("h:i A"); 
$msg = 'on '.date('M j, Y')." Information from contact form: Name: $name With the email address of $email Wrote this message: $message";

mail($to, $subject, $msg, $headers);

$to = 

Open in new window


in addition for mail address validation following code will be useful:
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
                 str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless 
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}

Open in new window


If you need anything else let me know.
0
 
re-searcherCommented:
Tips: in Php single quotation and double quotation have different functionality.
don't you double quotation if you can. and use it just for times you need using inline variable assignment.

if will optimize your coding.
0
 
JohnMac328Author Commented:
Same error for each one
0
 
re-searcherCommented:
would you mind add error_reporting(E_ALL); on first line of php and add all errors here?
0
 
JohnMac328Author Commented:
I am not getting any detail error - here is the first two line of the code

<?php
error_reporting(E_ALL);
0
 
JohnMac328Author Commented:
Wait - got it
0
 
JohnMac328Author Commented:
Thanks for the help
0
 
re-searcherCommented:
Ok
0
 
re-searcherCommented:
Would you mind tel me what's your problem? and which error occur when you run our codes?
0
 
JohnMac328Author Commented:
It's early and the error was between the keyboard and the chair :) - liveaspankaj: solution was the first one to get it going - Thanks again
0
 
re-searcherCommented:
Any time,

have a great day
0
 
JohnMac328Author Commented:
You too
0
 
liveaspankajCommented:
welcome
i guess no one took the effort to go to the error info page link provided in you issue :)
0
All Courses

From novice to tech pro — start learning today.