0

I am currently using this php code to send a mail from a form on my website, and it works fine, with one exception : when we receive the email it shows as sent by "webmaster@mydomain.com" instead of the user's email.

This is the php :

if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["vphone"]==""||$_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 "Invalid Sender's Email";
}
else{
$subject = "Contact site";
$message = "\n\nMessage from: ".$_POST["vname"]."\nPhone: ".$_POST["vphone"]."\nEmail: ".$_POST["email"]."Message:\n\"".$_POST["msg"]."\"";
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("contact@mydomain.com", $subject, $message, $headers);
echo "Email sent !";
}
}
}
Saryk
  • 345
  • 1
  • 12

0 Answers0