I am having a contact form problem.
For some reason, the messages I receive from my contact form have no FROM information, even though I seem to have it set in the form.
What am I doing wrong?
PHP Code:
<?php
// if form is submitted
if($_POST['submit'])
{
$sender = "From: " . $field_1 . " <" . $field_2 . ">";
// if you are using these values to add into a database as well, you may want some more security!
foreach($_POST as $key => $value)
$$key = htmlspecialchars($value);
// required fields
if($field_1 != '' && $field_2 != '' && $field_3 != '' && $field_4 != '')
{
$message_body .= $field_1 . ' <' . $field_2 . ' > ' . ' wrote the following message: ' . "\r\n";
$message_body .= 'Comments: '. $field_4 . "\r\n";
// send mail
//mail($to_email, 'Contact - ' . $field_3, $message_body);
mail("info@mydomain.org", $field_3, $message_body, $sender);
$msg = '<p>We have received your information. We will try and answer your question or comments ASAP.</p>';
$msg .= '<p>Thank you.</p><p><b>You wrote the following:</b>';
$msg .= '<div class="followup">';
$msg .= '<p><b>Full Name:</b> '. $field_1 .'</p>';
$msg .= '<p><b>Email</b>: ' . $field_2 . '</p>';
$msg .= '<p><b>Subject</b>: ' . $field_3 . '</p>';
$msg .= '<p><b>Comments:</b><br /> ' . $field_4 . '</p>';
$msg .= '</div>';
}
// if a required field wasn't filled in
else
$error = '<p class="error">Please make sure all fields are filled in.</p>';
}
if(isset($msg))
echo $msg;
else
{
if(isset($error))
echo $error;
?>
Thanks
Bryan