1

I'n brand-new to the web design world, and I'm having some trouble with my HTML email form. I'm uncertain whether the problem is in the HTML or the PHP (or both!), So I'm posting both. Any pointers will be greatly appreciated!

Here's my HTML form:

<form name="send_form_email" method="request"
action="send_form_email.php">
  <tr>
    <td width="375px" height="25px" style="text-align:right;background-color:#98CE32;"> Nom:     <input type="text"
name="nom" autofocus></td>
    <td rowspan="3" width="375px" height="75px" style="text-align:center;font-size:25px;    background-color:#98CE32;">819.352.4711</td>
  </tr>
  <tr>
    <td width="375px" height="25px" style="text-align:right;background-color:#98CE32;">     Téléphone: <input type="text"
name="telephone"></td>
  </tr>
  <tr>
    <td width="375px" height="25px" style="text-align:right;background-color:#98CE32;">     Courriel: <input type="text"
name="courriel"></td>
  </tr>
  <tr>
    <td width="375px" height="225px" align="right" style="background-color:#98CE32;"><textarea name="message" cols="45" rows="14" placeholder="Questions? Commentaires?"></textarea></td>
    <td width="375px" height="225px" align="left" style="background-color:#98CE32;"><img src="excavation_rd.jpg" alt="excavationrd"></td>
  </tr>
  <tr>
    <td width="375px" height="25px" align="center" style="background-color:#98CE32;"><input type="submit" value="Envoyer" name="Envoyer">
    <input type="reset" value="Effacer" name="Effacer"></form></td>

And here's my PHP code:

<?php
if(isset($_REQUEST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "*****s@yahoo.ca";
$email_subject = "Nouveau Message de www.*****.com";


function died($error) {
    // your error code can go here
    echo "Nous sommes désolés, mais il y a des erreurs dans le formulaire envoyé. ";
    echo "Voici les erreurs.<br /><br />";
    echo $error."<br /><br />";
    echo "SVP corrigez ces erreurs.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_REQUEST['nom']) ||
    !isset($_REQUEST['telephone']) ||
    !isset($_REQUEST['courriel']) ||
    !isset($_REQUEST['message'])) {
    died('Désolé, mais il y a une erreur!.');      
}

$first_name = $_REQUEST['nom']; // required
$telephone = $_REQUEST['telephone']; // required
$email_from = $_REQUEST['courriel']; // not required
$comments = $_REQUEST['message']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Le courriel que vous avez fourni ne semble pas être valide.<br />';
  }
$string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Le nom que vous avez entré ne semble pas être valide.<br />';
  }
  if(strlen($comments) < 2) {
$error_message .= 'Votre message ne semble pas être valide.<br />';
  }
  if(strlen($error_message) > 0) {
died($error_message);
  }
$email_message = "Détails ci-bas.\n\n";

    function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "nom: ".clean_string($first_name)."\n";
$email_message .= "telephone: ".clean_string($email_from)."\n";
$email_message .= "courriel: ".clean_string($telephone)."\n";
$email_message .= "message: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

Merci de nous avoir contacté! Nous vous répondrons sous-peu!

<?php
}
?>

Any ideas?

Nube
  • 11
  • 1
  • 2
    a) give your form a method (e.g. `method="post"`) and b) post the errors you're getting. – j08691 May 03 '13 at 15:53
  • `method="request"` is NOT a valid HTTP method. you want `POST`. plus, do **NOT** suppress errors with `@`. – Marc B May 03 '13 at 15:55

3 Answers3

1

Try method="get" or method="post". Either of those will populate the global $_REQUEST[] in PHP.

Biotox
  • 1,563
  • 10
  • 15
Jason
  • 151
  • 1
  • 4
0

Change this

<form name="send_form_email" method="request" action="send_form_email.php">

to

<form name="send_form_email" method="POST" action="send_form_email.php">
Vivek Sadh
  • 4,230
  • 3
  • 32
  • 49
0

request is not a valid value for the method attribute. It must be either get or post.

A form element is not allowed to have a <tr> element as a child. Either the entire table must be contained in the form or the form must be entirely contained within a table cell. When trying to recover from this error, some browsers will move the form outside the table while leaving the inputs behind. This renders both the form and the inputs useless.

Both these problems would have been highlighted if you had used a validator to perform basic QA of your HTML.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335