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 = "info@recruitment4less.co.uk"; 
$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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

<?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 = "info@recruitment4less.co.uk"; 
    $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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.