Contact Form send via email using PHP

I am a beginner with PHP and trying to set up a contact form that will send the information inputted to an email address using a PHP script after validating using regular expressions, then open a "thank you" page. I've been trying to follow a tutorial on the following page: http://myphpform.com/php-form-tutorial.php

I've set up a test server using Uniform Server and established using a mailtest.php file that the mail server is working. But try as I might I can't get my PHP script to work with my form so would really appreciate any advice anyone can offer.

HTML - page at: http://www.plymouthparentpartnership.org.uk/index.php?p=32_3

<span class="title">Parent Request for Involvement in Parenting Programmes</span>
<p>If you are a <span style="font-weight: bold;">Parent</span>, please complete this form to request a Parenting Programme.</p>
<p>If you are a <span style="font-weight: bold;">Professional</span>, please use the <a href="http://www.plymouthparentpartnership.org.uk/index.php?p=32_4" title="Professional Form to request Parenting Programme">Professional Form</a> to request a Parenting Programme.</p>
<div style="WIDTH: 75%" class="box-round-corner">
  <form action="parent-p-programme.php" method="post">
    <div>
      <div>
        <div>
          <table width="100%" cellspacing="0" cellpadding="2" border="0">
            <tbody>
              <tr>
                <td colspan="2"> <span class="error">* required field.</span></td>
              </tr>
              <tr>
                <td>Name:</td>
                <td>
                  <input type="text" name="name" size="35" /> <span class="error"> *</span></td>
              </tr>
              <tr>
                <td style="VERTICAL-ALIGN: top">Telephone Number or<br />
                   Mobile number if main number:</td>
                <td>
                  <input type="text" name="tel" size="35" /> <span class="error"> *</span></td>
              </tr>
              <tr>
                <td>Mobile Number:</td>
                <td>
                  <input type="text" name="mobile" size="35" /></td>
              </tr>
              <tr>
                <td>Email Address:</td>
                <td>
                  <input type="email" name="email" size="35" /></td>
              </tr>
              <tr>
                <td>Course Required:</td>
                <td>
                  <select name="course">
                    <option selected="selected">Please select course</option>
                    <option>Incredible Years</option>
                    <option>Strengthening Families 10-14 years</option>
                  </select> <span class="error"> *</span></td>
              </tr>
              <tr>
                <td style="VERTICAL-ALIGN: top">Date of Birth of<br />
                   Child / Young Person:</td>
                <td>
                  <input type="text" name="dob" size="35" /> <span class="error"> *</span></td>
              </tr>
              <tr>
                <td style="VERTICAL-ALIGN: top">Additional Information:</td>
                <td>
                  <textarea name="info" rows="5" cols="32"></textarea></td>
              </tr>
            </tbody>
          </table>
          <p>We aim to respond to your enquiry within 2 working days.</p>
          <p>
            <input type="submit" value="Send Request" />
            <input type="reset" value="Clear Form" /></p></div> </div> </div>
  </form></div>

PHP Script

<?php
/* Parent request for Parenting Programme */

/* Set e-mail recipient */
$myemail  = "myemailaddress@gmail.com"; // dummy email


/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name"); // required
$tel = check_input($_POST['tel'], "Enter your telephone number or mobile number if this is your main number"); // required
$mobile = check_input($_POST['mobile']);
$email = check_input($_POST['email']);
$course = check_input($_POST['course'], "Select course required"); // required
$dob = check_input($_POST['dob'], "Enter young persons date of birth"); // required
$info = check_input($_POST['info']);

/* If tel no is not valid show error message */
if (!preg_match("/([0-9 ]{6})?([0-9]{6})/", $tel))
{
    $tel = '';
}

/* Validate mobile no (optional) */
if (!preg_match("/([0-9 ]{6})?([0-9]{6})/", $mobile))
{
    $mobile = '';
}

/* If e-mail is not valid show error message (optional) */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    $email = '';
}

/* Email Message */
$message = "Request for $course

Name: $name
Tel No: $tel
Mobile: $mobile
Email: $email

Course: $course
Young Person's Date of Birth: $dob

Additional information: 
$info

End of message
";

/* Send message using mail () function */
mail($myemail, $message);

/* Redirect to thank you page */
header('Location: 32_5.html');
exit();

?>


<?php
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

The "thank you" for submitting page pops up after completing fields and it seems to recognise where fields are not filled in, but validation doesn't seem to be properly working either.

Thank You Page after form submission

<span class="title">Parenting Programme Request</span>
<p>Your request for a Parenting Programme was sent.</p>
<p>We aim to respond to your request within 2 working days.</p>

The PHP script is not sending any emails, when I test locally. Spent all evening looking at it, but just can't see what I'm doing wrong. So thanking you in advance for any help or advice anyone can offer.

Answers


The php mail function requires 3 parameters, you've only given it 2.

http://www.php.net/manual/en/function.mail.php

I tested it with unix mail and it worked fine once a subject was applied.


Need Your Help