Jump to content

Recommended Posts

Posted

The following short script is something I inherited from a website I am updating for my client. My client claims he receives the last "error message" in the script along with messages he even DOES receive!

 

I am not expert enough with PHP to even start to analyze the problem!

 

Can you help?

 

Alfie

 

<?php

$to = "chmyrockin@blueridge.net" ;

$from = $_REQUEST['email'] ;

$name = $_REQUEST['name'] ;

$headers = "From: $from";

$subject = "Information About Chimney Rock Inn";

 

$fields = array();

$fields{"name"} = "name";

$fields{"phone"} = "phone";

$fields{"email"} = "email";

$fields{"arrival"} = "arrival";

$fields{"DateLeaving"} = "DateLeaving";

$fields{"roomtype"} = "roomtype";

$fields{"adults"} = "adults";

$fields{"children"} = "children";

$fields{"homenumber"} = "homenumber";

$fields{"cottagetype"} = "cottagetype";

$fields{"comments"} = "comments";

 

 

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

 

$headers2 = "From: chmyrockin@blueridge.net";

$subject2 = "Thank you for contacting us";

$autoreply = "Thank you for contacting us.

You will be receiving more information shortly from us.";

 

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 for Us! You will be contacted soon about your request" ;}

else

{print "We encountered an error sending your mail, please notify chmyrockin@blueridge.net"; }

}

}

?>

Posted
y client claims he receives the last "error message" in the script along with messages he even DOES receive!

Can you rephrase this? Are you saying that users still receive error messages within the form, even when the form successfully submits and the client receives emails from the form?

Posted

I dont think this will cause any errors, but the line

 

$headers = "From: $from"; 

 

isnt printing whats in the variable, rather literally "From: $from" since the variable isnt escaped.

 

Which might cause the line:

$send = mail($to, $subject, $body, $headers); 

 

to fail (.?) I've never sent headers using mail() before, and would also explain why send2 works (uses a different header ($headers2))

 

My suggestion:

 

change:

 

$headers = "From: $from"; 

 

to:

 

$headers = "From: " . $from; 

Posted
Change to: $headers = "From: " . $from;

 

If you put variables in double quotes they usually get parsed instead of literal '$from' it will be replaced with the variable's value. So that doesn't make any difference.

 

We encountered an error sending your mail, please notify chmyrockin@blueridge.net

 

If your client is receiving this message then maybe something wrong with your server's PHP Mail() configuration?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...