Adding fields to contact 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
Stefan83
Forum Newbie
Posts: 5
Joined: Tue Apr 03, 2007 10:13 am

Adding fields to contact form

Post by Stefan83 »

Hi

I have added two fields to a contact form (telephone number and a 'product' dropdown) but I am having difficulties editing the sendmail.php file so the email is delivered with the extra data. Can anyone help? Thanks!

Code: Select all

 <?php
          error_reporting(E_NOTICE);
          function valid_email($str)

          {
          return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
             }

          if($_POST['name']!='' && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && strlen($_POST['comment'])>1)

          {
              $to = $_POST['receiver'];
              $headers =  'From: '.$_POST['email'].''. "\r\n" .
                'Reply-To: '.$_POST['email'].'' . "\r\n" .
                      'X-Mailer: PHP/' . phpversion();
              $subject = "Contact Form";
              $message = htmlspecialchars($_POST['comment']);
             
        if(mail($to, $subject, $message, $headers))
              {
                  echo 1; //SUCCESS
              }
              else {
                  echo 2; //FAILURE - server failure
              }
          }
          else {
             echo 3; //FAILURE - not valid email

          }

      ?>

Post Reply