I know there have been a few posts regarding this subject, but as a complete newbie to scripting, i've been trying to put something together that works.
I finally have a script that is doing mostly what i need it to do. It actually sends the form data! However, when i receive the e-mail, the from header doesn't contain the e-mail address typed into the form so it's simpler to reply.
I've put together a few example scripts to create the script i'm using, so some of the code may actually be irrelevant or ugly.... and trying to implement the server hosts parameters too...
Anyway, Basic HTML form:
<form action="emailform_testing2.php" method="post" name="contact" id="contact">
<label>Name:</label><br>
<input type="text" name="Name" size="30"><br>
<label>Company:</label><br>
<input type="text" name="Company" size="30"><br>
<label>Telephone:</label><br>
<input type="text" name="Telephone" size="30"><br>
<label>E-mail:</label><br>
<input type="text" name="Email" size="30"><br>
<label>Message:</label><br><textarea name="Message" cols="50" rows="5"></textarea>
<br>
<p id="buttons"><input type="submit" value="Send Message" ><input type="reset" value="Clear Form" ></p></p>
</form>
PHP script:
<?php
$EmailTo = "testing@mydomain.com";
$Subject = "Web Contact Enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Company = Trim(stripslashes($_POST['Company']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Email_from = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "e-mail: ";
$Body .= $Email_from;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
//Create header that puts email in From box along with name in parentheses and sends bcc to alternate address
$from='From: '. $Email_from . "(" . $Name . ")" . "\r\n" . 'Bcc: testing@mydomain.com' . "\r\n";
// send email
ini_set("sendmail_from", $from);
$success = mail($EmailTo, $Subject, $Body, "-f".$from);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
So... my question is, does this do what i think it's suppossed to do and add the email input from the form to the from header allowing me to reply directly to the e-mail? I have a feeling i maybe confusing things with the $Email_from and the $from bits.
My next step is sorting out validation, but i want to get the basics right first.