I bought this book PHP fast & easy since I am just starting with php and in the book they show you the following code for creating a simple contact form. Everything works and looks good but it does not do anything, when you submit the form you get the confirmation "mail has been sent" but I don't receive anything. I don't see a piece of code that connects to the mail server perhaps this is the problem. Could somebody look over the code, it's very basic compared to others I have seen here, looking at other codes did not do me any good since most of the time I can't make out what some of the variables are for.
I just want a simple feedback/contact form and perhaps once I get this one working I can expand on it to create other forms. Thank you all in advance.
<?
$form_block = "
<FORM METHOD=\"POST\" ACTION=\"$_SERVER[PHP_SELF]\">
<P><strong>Your Name:</strong><br>
<INPUT type=\"text\" NAME=\"sender_name\" size=30></P>
<P><strong>Your E-Mail:</strong><br>
<INPUT type=\"text\" NAME=\"sender_email\" size=30></P>
<P><strong>Your Topic:</strong><br>
<INPUT type=\"text\" NAME=\"sender_topic\" size=30></P>
<P><strong>Message:</strong><br>
<TEXTAREA NAME=\"message\" COLS=30 ROWS=6 WRAP=virtual>
</TEXTAREA></P>
<INPUT type=\"hidden\" name=\"op\" value=\"ds\">
<P><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send this message\"></P>
</FORM>";
if ($POST[op] != "ds") {
// they need to see the form
echo "$form_block";
} else if ($POST[op] == "ds") {
// check value of $POST[sender_name]
if ($POST[sender_name] == "") {
$name_err = "<font color=red>Please enter your name!
</font><br>";
$send = "no";
}
// check value of $POST[sender_email]
if ($POST[sender_email] == "") {
$email_err = "<font color=red>Please enter your e-mail!
</font><br>";
$send = "no";
}
// check value of $POST[sender_topic]
if ($POST[sender_topic] == "") {
$topic_err = "<font color=red>Please enter your Topic!
</font><br>";
$send = "no";
}
// check value of $POST[message]
if ($POST[message] == "") {
$message_err = "<font color=red>Please enter your message!
</font><br>";
$send = "no";
}
if ($send != "no") {
// it's okay to send, so build the mail
$msg = "E-Mail sent from website\n";
$msg .= "Sender's Name: $POST[sender_name]\n";
$msg .= "Sender's E-mail: $POST[sender_email]\n";
$msg .= "Sender's Topic: $POST[sender_topic]\n";
$msg .= "Message: $POST[message]\n\n";
$to = "support@mysite.com";
$subject = "Contact Form";
$mailheaders = "From: My website <> \n";
$mailheaders = "Reply-to: $_POST[sender_email]\n\n";
//send the mail
mail ($to, $subject, $msg, $mailheaders);
//display confirmation to user
echo "<P>Mail has been sent!</P>";
} else if ($send == "no") {
//print error messages
echo "$name_err";
echo "$email_err";
echo "$topic_err";
echo "$message_err";
echo "$form_block";
}
}
?>