Page 1 of 1

Browser error with PHP email script

Posted: Tue Jan 05, 2010 6:53 am
by normcity
I keep getting an error when I run the following PHP script. The browser says there is an error on line 53 - which is the mail($EmailTo,$Subject,$Body,$name); line, but I can't see anything wrong there, or subsequently.

Can anybody help me out with where I'm going wrong?

Thanks!

<?php
$EmailFrom = $_POST['email'];
$EmailTo = 'relevant email address here';
$Subject = 'Contact Request';
$name = $_POST['name'];
$org = $_POST['org'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$comments = $_POST['comments'];
$mail_list = $_POST['mail_list'];

$headers = "From: " . $EmailFrom. "\r\n" . 'X-Mailer: PHP/' . phpversion('5.0');

$Body .= "---------------------------";
$Body .= "\n";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Organisation: ";
$Body .= $org;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "Contact number: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "E-mail: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $comments;
$Body .= "\n";
$Body .= "\n";
$Body .= "Mail List: ";
$Body .= $mail_list;
$Body .= "\n";
$Body .= "---------------------------";
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="../tpollo.css" />
<title>T'Pollo - Great Northern Comedy</title>
</head>
<body>
<?php
mail($EmailTo,$Subject,$Body,$EmailTo);

echo("<p class=conf>Thank you. We will contact you shortly.<br />
<a href=../index.htm>Click here to return to the website.</a></p>");
?>
</body></html>

Re: Browser error with PHP email script

Posted: Tue Jan 05, 2010 8:27 am
by penkomitev
There has to be something with the contents of the variables you are using as arguments of mail().
However, due to the lack of additional information, I can't say anything in particular.

I suggest that you format your code in a

Code: Select all

so it is easier to read. Also, try finding the mistake. "There is an error" is pretty vague. You have to specify what kind of error it is so we can provide assistance.

Regards

Re: Browser error with PHP email script

Posted: Tue Jan 05, 2010 8:42 am
by peterg012
Hi,

On the line where the error is:

Code: Select all

mail($EmailTo,$Subject,$Body,$EmailTo);
I notice that the 4th parameter is the "TO" address. You have created a $headers var, but have not used it. Change you line to the following as a test:

Code: Select all

 
$Header = "From: $EmailTo";
$Send = mail($EmailTo,$Subject,$Body,$Header);
 
if(!$Send)
{
   print "Sorry an error occurred!";
}
Let me know..Cheers

Re: Browser error with PHP email script

Posted: Tue Jan 05, 2010 2:09 pm
by normcity
Thanks for your comments.

This is the error message I am getting:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for email address in C:\apachefriends\xampp\htdocs\....php on line 53

This is on the testing server on my computer, but I've tested it on the web server too.

I will re-check everything but if you can see what's wrong from this please let me know.

Cheers.

Re: Browser error with PHP email script

Posted: Tue Jan 05, 2010 3:30 pm
by AbraCadaver
normcity wrote:Thanks for your comments.

This is the error message I am getting:

Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for email address in C:\apachefriends\xampp\htdocs\....php on line 53

This is on the testing server on my computer, but I've tested it on the web server too.

I will re-check everything but if you can see what's wrong from this please let me know.

Cheers.
Your email server is either not configured to relay email for that email address or it requires authentication. You can check out the PEAR Mail package or Swift Mailer