I am a real noob when it comes to PHP but here is my problem -
the form "from address" reads as [email protected], and This causes a) a delivery failure notice and b) one cannot click "reply" as the from address is not the person's address who completed the form.
Here is my code can anyone point out why this is happening and how to fix it?
thank you so much in advance
<?php
/* Set e-mail recipient */
$myemail = "[email protected]";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['subject'], "Enter a subject");
$email = check_input($_POST['email']);
$message = check_input($_POST['message'], "Write your message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
Name: $name
E-mail: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: thanks.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
And HTML
<form class="email" action="mailer.php" method="post">
<p align="center"><span class="style27"><strong>Name:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="name" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>E-mail:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="email" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>Subject:</strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<input style="width:50%;" type="text" name="subject" />
</strong></span>
</div>
<p align="center"><span class="style27"><strong>Message: </strong></span></p>
<div align="right"><span class="style21 link_title"><strong>
<textarea style="width:50%;"= name="message"></textarea>
</p>
<input class="send" type="submit" value="Send">
</strong></span>
</div>
</form>