What code can I use to have a senders email show up in the From line of my new email and the Subject field show up in the Subject line of the new email? And, where should I place this code?
Here is my processor.php
I got most of this figured TNT, the subject line was easy enough but I am having trouble with the from line.
I understand that you need to use the $headers variable to change this but I can't get the from e-mail to change. I get this: $frommail@web12.justhost.com instead of the $frommail variable replacing everything.
What code can I use to have a senders email show up in the From line of my new email and the Subject field show up in the Subject line of the new email? And, where should I place this code?
Here is my processor.php
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
// File upload handling
if($_FILES['field_16']['name']!=''){
$field_16_filename = "file_16_".date("sihdmY").substr($_FILES['field_16']['name'],strlen($_FILES['field_16']['name'])-4);
if(!move_uploaded_file($_FILES['field_16']['tmp_name'], "./files/".$field_16_filename)){
die("File " . $_FILES['field_16']['name'] . " was not uploaded.");
}
}
mail("my@emailaddress.com","phpFormGenerator - Form submission","Form data:
Title:: " . $_POST['field_1'] . "
First Name:: " . $_POST['field_2'] . "
Last Name:: " . $_POST['field_3'] . "
Company Name:: " . $_POST['field_4'] . "
Address:: " . $_POST['field_5'] . "
City:: " . $_POST['field_6'] . "
State:: " . $_POST['field_7'] . "
Zip Code:: " . $_POST['field_8'] . "
Telephone:: " . $_POST['field_9'] . "
Fax:: " . $_POST['field_10'] . "
Email:: " . $_POST['field_11'] . "
How did you hear about us?: " . $_POST['field_12'] . "
Subject:: " . $_POST['field_13'] . "
Message:: " . $_POST['field_14'] . "
How would you like to be contacted?: " . $_POST['field_15'] . "
Upload File:: ".$where_form_is."files/".$field_16_filename." (original file name: " . $_FILES['field_16']['name'] . ")
");
include("index.html");
}
else {
echo "Invalid Captcha String.";
}
?>
Thanks for any help that can be provided.
Start here:
http://www.php.net/manual/en/function.mail.php
There are good examples and you should be able to figure it out.
I got most of this figured TNT, the subject line was easy enough but I am having trouble with the from line.
I understand that you need to use the $headers variable to change this but I can't get the from e-mail to change. I get this: $frommail@web12.justhost.com instead of the $frommail variable replacing everything.
this is what I have on the php side:
$frommail=$_POST['field_3'];
$headers .= 'From: $frommail' . "\r\n";
E-mail:: " . $_POST['field_3'] . "
Thanks for your reply
$headers .= "From: " . $frommail . "\r\n";
Thanks a lot TNT. For the record here is the solution I got if anyone else is watching this:
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
$subject=$_POST['field_1'];
$frommail=$_POST['field_4'];
$headers .= "From: " . $frommail . "\r\n";
// File upload handling
if($_FILES['field_9']['name']!=''){
$field_9_filename = "file_9_".date("sihdmY").substr($_FILES['field_9']['name'],strlen($_FILES['field_9']['name'])-4);
if(!move_uploaded_file($_FILES['field_9']['tmp_name'], "./files/".$field_9_filename)){
die("File " . $_FILES['field_9']['name'] . " was not uploaded.");
}
}
mail("your@mailserver.com",$subject,
"
Name:: " . $_POST['field_2'] . " of Website:: " . $_POST['field_7'] . "
E-mail:: " . $_POST['field_4'] . "
-----------------------------------------------
Gender:: " . $_POST['field_3'] . "
-----------------------------------------------
Location:: " . $_POST['field_5'] . "
-----------------------------------------------
How hear about us?: " . $_POST['field_6'] . "
-----------------------------------------------
Comments:: " . $_POST['field_8'] . "
Upload Box:: ".$where_form_is."files/".$field_9_filename." (original file name: " . $_FILES['field_9']['name'] . ")
",$headers);
include("confirm.html");
?>
This will make the 'subject' of the e-mail and the 'from' be from the information entered in the form.