2

I have this simple form code here

<?php

$EmailFrom = "form@form.com";
$EmailTo = "s@outlook.com";
$Subject = "Form";
$Name = Trim(stripslashes($_POST['Name'])); 
$Budget = Trim(stripslashes($_POST['Budget'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Budget: ";
$Body .= $Budget;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}

?>

And I was wondering how to make the from address in the top the same as the one submitted.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicole
  • 23
  • 2

1 Answers1

0

If I understand correctly, you can do away entirely with this variable:

$EmailFrom = "form@form.com";

And this revised mail() function should do what you're asking:

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: " . $Email . "\r\n");

Note I've used the following variable you've already declared:

$Email = Trim(stripslashes($_POST['Email'])); 
David Wilkinson
  • 5,060
  • 1
  • 18
  • 32