Log in

View Full Version : How do I fix code so emails arrive showing the email field in the "TO" inbox?



WolfMama
03-10-2007, 06:46 PM
Hello. With my previous host provider, I'd used a CGI script. This one uses PHP, and they provide the PHP script. I've made all the necessary changes to my form to accomodate their script, however, I have one problem:

Utilizing their script (below), how do I direct the emails to show the email address of the sender? IOW, one of the fields on the form is the email field. On my previous server, it was setup to show the email address field, when I received the email - it would appear to "come" from that person's email address. This was very useful to us for a few reasons.

What do I need to add to my form, or to this script, in order to make it arrive as noted above?

<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET"){
$query_vars = $_GET;
} elseif ($request_method == "POST"){
$query_vars = $_POST;
}
reset($query_vars);
$t = date("U");

$file = $_SERVER['DOCUMENT_ROOT'] . "/../data/gdform_" . $t;
$fp = fopen($file,"w");
while (list ($key, $val) = each ($query_vars)) {
fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\n");
fputs($fp,"$val\n");
fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\n");
if ($key == "redirect") { $landing_page = $val;}
}
fclose($fp);
if ($landing_page != ""){
header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
} else {
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}


?>


Thanks!

Blake
03-10-2007, 06:53 PM
mail( [to], [subject], [message], "From: [from]" );

[to] - the email you're sending the message to.
[subject] - the message subject.
[message] - the message body
[from] - the email address you want the message to be from.

Here's an example:



$from = "me@somewhere.com";
$to = "you@somewhereelse.com";
$message = "I bent my wookie!";
$subject = "Hello there!";

mail($to, $subject, $message, "From: $from");

WolfMama
03-10-2007, 09:59 PM
But, that would give the same email address all the time? That is, if I'm reading it correctly.

I'd like it to give the email address that the person fills in on the form.

Blake
03-10-2007, 10:04 PM
That's exactly what it does. It's only meant to be an example. Instead of putting in the same email address every time, you'll need to retrieve the email that the user entered in the form.

For example, if the field's name is email, you would write



$from = $_REQUEST['email'];