July 15, 200917 yr Hi, I am utterly awful in php however I have found this bit of code and modified it to do what I want: <?php $to = "--Removed the e-mail address--"; $from = $_POST["fmail"] ; $name = $_POST["fname"] ; $headers = "From: $from"; $subject = "Contact Form"; $fields = array(); $fields{"fname"} = "Name"; $fields{"fmail"} = "Email"; $fields{"fphone"} = "Phone"; $fields{"ftype"} = "Type of Query"; $fields{"fmessage"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $ { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } $headers2 = "From: noreply@YourCompany.com"; $subject2 = "Thank you for contacting us"; $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com"; 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) {header( "Location: http://google.com" );} else {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; } } } ?> My only problem is that on the e-mail it sends contains extra spaces before each line (with exception of the first line). Message: We have received the following information: Name: Name Email: e-mail@www.com Phone: Phone Number Type of Query: Catering Message: Message Content Any ideas as to why? Thanks in advance.
July 15, 200917 yr $body = "We have received the following information:\n\n"; foreach($fields as $a => $ { $body .=$b."\n"; } [/code] Try changing the $body line to the above! Sam
July 15, 200917 yr Author Unfortunately that gives this error, line 22 is the line with the "$body =..." "Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/vhosts/anlens.freeoda.com/index.php on line 22".
July 15, 200917 yr $body = "We have received the following information:\n\n"; foreach($fields as $value) { $body .= $value . "\n"; } Try that ... (Sorry) [edit] had to change $b to $value as this forum keeps changing my code :S [/edit]
July 15, 200917 yr Author Exactly the same error. EDIT: It had the same error until you edited it, sorry for the confusion.
July 15, 200917 yr Author Thanks, that didn't quite work as it removed the submitted data, I managed to fix it with this though: $body = "We have received the following information:\n\n"; foreach($fields as $a => $value) { $body .= $value . ": " . $_REQUEST[$a] . "\n"; } Thanks for the help once more, I'm starting to like php, I might have to put some time in to learning it.
Create an account or sign in to comment