Jump to content

help on php form to mail please


SAB206

Recommended Posts

Hi all, I'm new to the site and PHP for that matter, so please bare with me  :D

 

I've set up a simple 'contact' form, which relays the information via PHP to my email account.

 

However, every time the form gets used, when the email comes through, the "FROM" field comes up with a random generic email address form the domain, as appose to what the person has entered in the 'email' field.

 

hope that makes sense :)

 

Please help.

 

HTML...

 

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body>

<form method="POST" action="mailer.php">
Name:
<input type="text" name="name" size="19"><br>
<br>
E-Mail:
<input type="text" name="email" size="19"><br>
<br>

<input type="checkbox" name="check[]" value="blue_color"> Blue<br>
<input type="checkbox" name="check[]" value="green_color"> Green<br>
<input type="checkbox" name="check[]" value="orange_color"> Orange<br>
<br>
<input type="radio" value="yes" name="radio"> YES<br>
<input type="radio" value="no" name="radio"> NO
<br>
<br>
<select size="1" name="drop_down">
<option>php</option>
<option>xml</option>
<option>asp</option>
<option>jsp</option>
</select><br>
<br>
Message:<br>
<textarea rows="9" name="message" cols="30"></textarea><br>
<br>
<input type="submit" value="Submit" name="submit">
</form>

</body>

</html>

 

and the PHP for it.

 

<?php
if(isset($_POST['submit'])) {

$to = "[email protected]"; 
$subject = "SAB-GRAPHICS MAIL";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$option = $_POST['radio'];
$dropdown = $_POST['drop_down'];

foreach($_POST['check'] as $value) {
	$check_msg .= "Checked: $value\n";
}

$body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";

echo "Data has been submitted to $to!";
mail($to, $subject, $body, '-f'.$email_field);

} else {
echo "blarg!";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/200227-help-on-php-form-to-mail-please/
Share on other sites

If you mean the actual body, where you' ve given the details, there is no reason why it would do this. Use print_r($_POST); aat the top of your process script tocheck wether the post vriables arebeing submitted properly.

 

If you mean the actual header of the email then you need to specify the headers of the email with the from, rather than the body.

 

Google: PHP Email Headers

For a lot of info on email headers.

 

-cb-

Your mail function is not right and this does happen under these conditions

This ...

mail($to, $subject, $body, '-f'.$email_field);

 

should be ...

mail($to, $subject, $body, 'From: $name_field <$email_field>\r\n');

 

you need something like

 

'From: Fred <[email protected]>\r\n'

 

you need the \r\rn & name<email>

 

Desmond

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.