PDA

View Full Version : Flash form to PHP file help



Domo
July 19th, 2003, 10:07 PM
Ive made a flash contact form that interacts with a "form.php" file after you hit "send" on the contact form.

Heres the code:


<html>
<head>
<title>Contact Form</title>
</head>

<body>
<?
$msg .= "Name: ".$_POST["name"]."\n";
$msg .= "Email: ".$_POST["email"]."\n";
$msg .= "Message: ".$_POST["message"]."\n";

$to = "domo@hotmail.com";
$subject = "Email from domo's site".$_POST["subject"];

$mailheaders .= "Reply-To: ".$_POST["email"]."\n\n";

$result = mail($to, $subject, $msg, $mailheaders);
?>
</body>
</html>

When someone uses this form and I receive their email in my outlook express... it always says From: Nobody.

Does anyone know how to change my code so that it is changed from "nobody" to the persons mail who sent it?

Also, I was wondering how to edit my code to make sure that the email I get includes the senders IP address, just in case C:-)

Thanks,

Domo

ahmed
July 20th, 2003, 03:08 PM
try this
<?php
mail($to, $subject, $msg,"From: $_POST['name'] <$_POST['email']>\r\n"."Reply-To: ".$_POST["email"]."\n\n");
?>

and $_SERVER['REMOTE_ADDR'] resolves the user's IP :)

Domo
July 20th, 2003, 03:35 PM
thanks :P ill try it out

Domo
July 20th, 2003, 03:39 PM
do i add that into my original code or just have that alone?

ahmed
July 20th, 2003, 03:47 PM
<?
$msg .= "Name: ".$_POST["name"]."\n";
$msg .= "Email: ".$_POST["email"]."\n";
$msg .= "Message: ".$_POST["message"]."\n";

$to = "domo@hotmail.com";
$subject = "Email from domo's site".$_POST["subject"];

$mailheaders .= "From: $_POST['name'] <$_POST['email']>\r\n"."Reply-To: ".$_POST["email"]."\n\n";

$result = mail($to, $subject, $msg, $mailheaders);
?>

Domo
July 20th, 2003, 05:12 PM
^Thanks for that!

Ill try it out and let you know how it goes

Domo
July 20th, 2003, 05:22 PM
hmm..

This is the error I get:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/domo/public_html/mx/form.php on line 15

Heres my code:


<?
$msg .= "Name: ".$_POST["name"]."\n";
$msg .= "Email: ".$_POST["email"]."\n";
$msg .= "Message: ".$_POST["message"]."\n";

$to = "domo@hotmail.com";
$subject = "Email from domo's site".$_POST["subject"];

$mailheaders .= "From: $_POST['name'] <$_POST['email']>\r\n"."Reply-To: ".$_POST["email"]."\n\n";

$result = mail($to, $subject, $msg, $mailheaders);

$_SERVER['REMOTE_ADDR']
?>
Think you can help me out?

Thanks :)

ahmed
July 20th, 2003, 07:00 PM
i don't see the purpose of the last line.. remove it and it should be fine

Domo
July 20th, 2003, 07:08 PM
I get the same error when it is removed.

ahmed
July 20th, 2003, 07:35 PM
I rewrote your script.. it's much cleaner now:
<?php

// define variables
$name = $_POST['name'];
$email = $_POST['email'];
$usr_subject = $_POST['subject'];
$message = $_POST['message'];
$IP = $_SERVER['REMOTE_ADDR'];

$to = "domo@hotmail.com";

// set $subject
$subject = "Email from domo's site $usr_subject";

// set $msg
$msg = "Name: $name \nEmail: $email \nIP: $IP\nMessage: $message";

// define mail headers
$mailheaders = "From: $name <$email>";

$result = mail($to, $subject, $msg, $mailheaders);

?>

the script above i know works, just tested it.. if it doesnt work for you, you're on your own ;)

ahmed
July 20th, 2003, 07:36 PM
and.. why do you set the "reply-to" to be the reciever's email??

Domo
July 20th, 2003, 10:24 PM
i dont know - rofl im kind of a noob to PHP but I intend to learn it all 100% :P.

Thanks for your help, its greatly appreciated.

Domo
July 20th, 2003, 10:25 PM
btw.. the script works :D