Jump to content

Could you check this script for me?


daddyalfie

Recommended Posts

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"; }

}

}

?>

Link to comment
Share on other sites

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; 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...