Jump to content


Photo

PHP Form Help


  • Please log in to reply
1 reply to this topic

#1 Yila

Yila
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 14 March 2006 - 02:18 PM

Hi,

I have the following code:

<form action="send.php">
<b>Full Name:</b><br>
<input type="text" name="name" size="25" value="">
<br><br>
    
<b>Email Address:</b><br>
<input type="text" name="email" size="25" value="">
<br><br>

<b>Subject:</b><br>
<input type="text" name="subject" size="35" value="">
<br><br>

<b>Message:</b><br>
<textarea name="message" cols="35" rows="6"></textarea>
<br><br>

<input type="submit" />
</form>

Send.php:
<?php

$name = $HTTP_POST_VARS['name'];
$email = 'From: '.$HTTP_POST_VARS['email'];
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];


$to = 'jibberish@you.com';
$body = 'Name: '.$name.'\n'
.'E-Mail Address: '.$email.'\n'
.'Message: \n \n'.$message;

mail($to, $subject, $body, $email);
?>

This is the email I get it:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Name: \nE-Mail Address: From: \nMessage: \n \n
[/quote]

Whats wrong?

Thanks. :)

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 March 2006 - 02:28 PM

What's wrong? Alot...

Read the comments in the following fixed code:
<?php
$name = $_POST['name'];  // use the superglobal $_POST
$email = 'From: '.$_POST['email'] . "\n";  // headers need to be terminated with a new-line character
$subject = striplashes($_POST['subject']); // use stripslashes or your email message may be peppered with backslashes
$message = stripslashes($_POST['message']);  // same as above


$to = 'jibberish@you.com';
$body = 'Name: '.$name."\n"
.'E-Mail Address: '.$email."\n"
."Message: \n \n".$message;  // the newline character needs to be surrounded by double quotes or it won't be inserted correctly

mail($to, $subject, $body, $email);
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users