mcabde
11-13-2007, 04:55 PM
This is my first time using PHP in a webpage. I am trying to set up a PHP based email form, but I am having some problems. The script seems to be working properly, but when I try to use the form I recieve the error message I created telling me that my email could not be sent. The message appears in a new page.
I would like to find out why the script is not being able to send messages to my email and I would like to find a way to have messages print to the screen like pop-up errors I would typically get on my computer, instead of in a new page.
My current PHP script looks like the following:
<?php
$to = "MY EMAIL HERE" ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Form Submission";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: ME";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible. If you have any more questions, please feel free to resubmit the contact form at any time.";
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 "Your message has been sent successfully. Thank you!";}
else
{print "We encountered an error sending your mail. Please make sure all fields are filled out correctly or try again later. Thank you."; }
}
}
?>
Any thoughts/suggestions/corrections would be appreciated. Thank you in advance.
I would like to find out why the script is not being able to send messages to my email and I would like to find a way to have messages print to the screen like pop-up errors I would typically get on my computer, instead of in a new page.
My current PHP script looks like the following:
<?php
$to = "MY EMAIL HERE" ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Form Submission";
$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";
$fields{"Message"} = "Message";
$body = "We have received the following information:\n\n";
foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: ME";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible. If you have any more questions, please feel free to resubmit the contact form at any time.";
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 "Your message has been sent successfully. Thank you!";}
else
{print "We encountered an error sending your mail. Please make sure all fields are filled out correctly or try again later. Thank you."; }
}
}
?>
Any thoughts/suggestions/corrections would be appreciated. Thank you in advance.
