Jump to content

Newbie Form Problem - Simple for you budding gurus =


wizpeep

Recommended Posts

Have configured a form handling script to send form result to my email.

Sends to the email ok but no form results in email just blank.

How can I rectify it????? 

below is the form and the php code

 

<html><body><font face=Arial size=1> 
<form method="post" action="contact.php"> 
<table align=center> 
<tr><td colspan=2 align=center bgcolor="cccccc"><strong>Enqury Form:</strong></td></tr> 
<tr><td>Name:</td><td><input size=25 name="Name"></td></tr> 
<tr><td>Email:</td><td><input size=25 name="Email"></td></tr> 
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr> 
<tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr> 
<tr><td>Send Info:<br></td><td><input type="radio" name="list" value="yes"> Yes <input type="radio" name="list" value="no"> No <br></td></tr> 

<tr><td colspan=2>Message:</td></tr> 
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr> 
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr> 
</table> 
</form> 
</body> 
</html> 

<?php 
$to = "[email protected]"; 
$subject = "Recruitment4less Enquiry form";

$Name = $_REQUEST['Name'] ;
$Company = $_REQUEST['Company'] ;
$Email = $_REQUEST['Email'] ;
$Phone = $_REQUEST['Phone'] ;
$Brochure = $_REQUEST['Brochure'] ;
$Message = $_REQUEST['Message'] ;

$headers = "From: $email"; 
$sent = mail($to, $subject, $message, $headers) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?> 

Wizpeep

You have your php on your page without checking whether form info was sent or not, so when page first loads, you're going to automatically get an email with a bunch of empty values.  Upon form submission you should have been receiving another email with actual stuff.  Are you not ending up with 2 emails? 

 

Also, use $_POST instead of $_REQUEST

 

<?php 
  // Move the PHP to the top, and check for a POST
  // I like this method better then checking for $_POST['send']
  // as some browsers don't send the submit buttons value
  if($_SERVER['REQUEST_METHOD'] == 'POST'){
    $to = "[email protected]"; 
    $subject = "Recruitment4less Enquiry form";

    //You don't actually build a message to send???
    //Try this:
    $message = "Name: ".$_POST['Name']."\n".
      "Company: ". $_POST['Company']."\n".
      "Email: ". $_POST['Email']."\n".
      "Phone: ". $_POST['Phone']."\n".
      "Brochure: ". $_POST['Brochure']."\n".
      "Message: ". $_POST['Message'];

    $headers = "From: ".$_POST['email']; 
    $sent = mail($to, $subject, $message, $headers) ; 
    if($sent){
      print "Your mail was sent successfully";
      exit;
    }else{
      print "We encountered an error sending your mail";
      exit;
    }
  }
?>
<html><body><font face=Arial size=1>
<form method="post">
<table align=center>
<tr><td colspan=2 align=center bgcolor="cccccc"><strong>Enqury Form:</strong></td></tr>
<tr><td>Name:</td><td><input size=25 name="Name"></td></tr>
<tr><td>Email:</td><td><input size=25 name="Email"></td></tr>
<tr><td>Company:</td><td><input size=25 name="Company"></td></tr>
<tr><td>Phone:</td><td><input size=25 name="Phone"></td></tr>
<tr><td>Send Info:<br></td><td><input type="radio" name="list" value="yes"> Yes <input type="radio" name="list" value="no"> No <br></td></tr>

<tr><td colspan=2>Message:</td></tr>
<tr><td colspan=2 align=center><textarea name="Message" rows=5 cols=35></textarea></td></tr>
<tr><td colspan=2 align=center><input type=submit name="send" value="Submit"></td></tr>
</table>
</form>
</body>
</html>

 

...i also removed the ACTION on the form tag, as it will post to itself by default

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.