I am using a contact form script I found on a tutorial, and it's working fine. The subject and message contact goes through, however the sender email doesn't. The sender name and email do not come through. When I check the email received from the form it says 'unknown sender' in the inbox, and when I view the message it says it was sent via the host.
Can anyone see where I am going wrong with this? I don't have much experience with contact forms and need it finished shortly for a client site.
HTML for the form is here:
<form action="#" id="form" method="post" name="form">
<input name="vname" placeholder="Your Name" type="text" value="">
<input name="vemail" placeholder="Your Email" type="text" value="">
<input name="sub" placeholder="Subject" type="text" value="">
<label>Your Suggestion/Feedback</label>
<textarea name="msg" placeholder="Type your text here...">
</textarea>
<input id="send" name="submit" type="submit" value="Send Feedback">
</form>
<h3><?php include "secure_email_code.php" ?>
</h3>
PHP code here:
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]=="" || $_POST["vemail"]=="" ||
$_POST["sub"]=="" || $_POST["msg"]=="")
{
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:'. $email2 . "
"; // Sender's Email
$headers .= 'Cc:'. $email2 . "
"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc@example.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>
If I hardcode the headers with something like email@provider.com
from the entry, the sent mail replaces it with @webhost.com
Example: I enter me@gmail.com
and the send email says it's from me@webhost.com
Is this an issue with my provider?
Code at the moment:
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields.";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:' . 'Ross@gmail.com' . "
"; // Sender's Email
$headers .= 'Cc: chad' . "
"; // Carbon copy to Sender
$from = $headers;
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc.murray.92@gmail.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>