Browser error with PHP email script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
normcity
Forum Newbie
Posts: 2
Joined: Tue Jan 05, 2010 6:30 am

Browser error with PHP email script

Post 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>
penkomitev
Forum Newbie
Posts: 6
Joined: Sat Dec 26, 2009 10:40 am
Location: Plovdiv, Bulgaria

Re: Browser error with PHP email script

Post 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
peterg012
Forum Newbie
Posts: 4
Joined: Thu Sep 06, 2007 12:52 am

Re: Browser error with PHP email script

Post 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
normcity
Forum Newbie
Posts: 2
Joined: Tue Jan 05, 2010 6:30 am

Re: Browser error with PHP email script

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Browser error with PHP email script

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply