Email form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
incarnadine
Forum Newbie
Posts: 2
Joined: Wed May 21, 2008 4:47 am

Email form

Post by incarnadine »

This will probably seem like an extremely simple request, but I'm a relative newbie when it comes to PHP. I'm looking to create a contact form that will email the information to a central email address. I've implemented one before, but for some reason - the new one I'm working on doesn't seem to work at all. Even though all I've done is modified the code. I can't seem to figure it out. Any help would be appreciated. Firstly, here's the code for the form\;

Code: Select all

<form name="form" method="post" action="email.php">
          <label class="label" for="name">name:</label>
          <input name="name" class="inputbox" id="name" type="text">
          <br />
          <label class="label" for="address">address:</label>
          <textarea name="address" rows="1" wrap="virtual" class="inputbox" id="address"></textarea>
          <br />
          <label class="label" for="postcode">postcode:</label>
          <input name="postcode" class="inputbox" id="postcode" type="text">
          <br />
          <label class="label" for="postcode">telephone:</label>
          <input name="telnumber" class="inputbox" id="telnumber" type="text">
          <br />
          <label class="label" for="email">email:</label>
          <input name="email" class="inputbox" id="email" type="text">
          <br />
          <label class="label" for="enquiry">enquiry:</label>
          <textarea name="enquiry" class="inputbox" id="enquiry" type="text"></textarea>
          <br />
          <label class="long" for="product">please tick if you would like a product CD:</label>
          <input name="product" id="checkbox" type="checkbox" value="yes" >
          <br />
          <input name="submit" type="submit" value="Submit" onClick="return validate(form)" class="button" id="submit" />
          <br />
        </form>
And the PHP code:

Code: Select all

<?php
 
$redirect = "http://www.weirs.co.uk/thanks.html";
 
$sendTo = "chris@themarketingcafe.net";
 
$subject = "Weirs Web Enquiry";
 
 
$headers = "From: " . $_POST["name"];
 
$headers .= "<" . $_POST["email"] . ">\r\n";
 
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
 
$headers .= "Return-Path: " . $_POST["email"];
 
 
 
$message = "Name: " . $_POST["name"] . "\n\n";
 
$message .= "Address: " . $_POST["address"] . "\n";
 
$message .= "Postcode: " . $_POST["postcode"] . "\n";
 
$message .= "Telephone number: " . $_POST["telnumber"] . "\n";
 
$message .= "Email address: " . $_POST["email"] . "\n";
 
$message .= "Request product CD: " . $_POST["product"] . "\n\n";
 
$message .= "Enquiry: " . $_POST["enquiry"];
 
 
mail($sendTo, $subject, $message, $headers);
header("Location:$redirect");
?>
Any ideas where I'm going wrong? PHP is enabled on the server, and as I've said the code has worked before on other projects I've used it with. It's probably not the best method, but my knowledge of PHP is extremely limited.

Thanks very much,
Chris
Scrumpy.Gums
Forum Commoner
Posts: 71
Joined: Thu Aug 30, 2007 2:57 pm
Location: Bristol, UK

Re: Email form

Post by Scrumpy.Gums »

Do you get any errors? You can put the mail function in an if statement to check if it was accepted for delivery

Code: Select all

 
if (mail($sendTo, $subject, $message, $headers))
     ...
else
     echo 'Error, could not send mail';
 
HTH
incarnadine
Forum Newbie
Posts: 2
Joined: Wed May 21, 2008 4:47 am

Re: Email form

Post by incarnadine »

I'm not getting any error message, and the code is redirecting to the thank you page, so I can't see where the error is lying.
Post Reply