PHP Contact form issue

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
bdavey311
Forum Newbie
Posts: 2
Joined: Fri Nov 07, 2008 1:03 pm

PHP Contact form issue

Post by bdavey311 »

View my new contact form here:
http://incentivo.dreamhosters.com/conta ... ctNEW.html

I'm trying to make it so when somebody selects "Classificação da Mensagem*" (basically it says "which department do you want this email to go") Once they click submit, the form is then emailed to whatever department they selected at the first drop down. I've played around with and have gotten stuck...Little help and thanks in advance.

Here is my PHP:

Code: Select all

<?php
header("Location: /contact/thankyou.html");
if(isset($_POST['submit']))
{
       $departments = array();
 
       // $departments[] = array('Department Name', 'department@email.address');
       $departments[] = array('Finance Department', 'domain@gmail.com');
       $departments[] = array('Main Office', 'domain@gmail.com');
       $departments[] = array('Billing', 'domain@gmail.com');
       $departments[] = array('Other', 'domain@gmail.com');
 
   $to = "domain@gmail.com";
 
       if (is_numeric($_REQUEST['questiondropdown']) AND $_REQUEST['questiondropdown'] != '-1' AND array_key_exists($_REQUEST['questiondropdown'], $departments))
       {
           $to = $departments[$_REQUEST['questiondropdown']][1];
       }
 
   $subject = "LoHi Scooters Contact Form";
   $first_name = $_POST['firstname'];
   $last_name = $_POST['lastname'];
   $contact_email = $_POST['emailaddress'];
   $phone_1 = $_POST['phone1'];
   $address_1 = $_POST['address1'];
   $address_2 = $_POST['address2'];
   $contact_city = $_POST['city'];
   $contact_state = $_POST['state'];
   $contact_zipcode = $_POST['zipcode'];
   $contact_question = $_POST['questiondropdown'];
   $contact_subject = $_POST['subject'];
   $contact_message = $_POST['message'];
   $preferred_checkbox = $_POST['check[]'];
 
   foreach($_POST['check'] as $value)
       {
               $check_msg .= "Preferred Method of Contact: $value\n";
   }
 
   $body = "First Name: $first_name\nLast Name: $last_name\nE-Mail: $contact_email\n\nPhone: $phone_1\nAddress 1: $address_1\nAddress 2: $address_2\nCity: $contact_city\nState: $contact_state\nZip Code: $contact_zipcode\n\nMy Question is Regarding: $contact_question\nSubject: $contact_subject\n$check_msg \nMessage: $contact_message\n";
 
   echo "Data has been submitted to $to!";
   mail($to, $subject, $body);
}
else
{
       echo "Please use the form to email us.";
}
?>
Here is the HTML where the form is:

Code: Select all

form method="post" action="/resources/scripts/mailer.php">
                
                
             <table width="465" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
                              <td width="465" height="40" align="left" valign="top" class="darkGreyLeftPanel"><p>Classifica&ccedil;&atilde;o da Mensagem*<br />
                                  <select name="questiondropdown" size="1" class="contactRightPanel">
                                    <option value="-1" selected="selected">Selecione...</option>
                  <?php
foreach ($departments as $id => $info)
{
    print('<option value="');
    print($id);
    print('">');
    print($info[0]);
    print('</option>');
    print("\n");
}
?>
                                                                    </select></p>
                                <p>Assunto*<br />
                                  <input name="subject" type="text" class="contactRightPanel" size="25" />
</p>
                                <p>Mensagem | Coment&aacute;rios*<br />
                                  <textarea name="message" cols="75" rows="3" class="contactRightPanel"></textarea>
                                </p>
                                <p>Dados Pessoais</p>
                                <table width="465" height="40" border="0" cellpadding="0" cellspacing="0">
                                  <tr>
                                    <td width="182" height="40" align="left" valign="top" class="darkGreyLeftPanel"><p>Nome*
                                      <input name="firstname" type="text" class="contactRightPanel" size="25" />
                                    </p></td>
                                    <td width="293" align="left" valign="top"><p>&nbsp;Sobrenome*<br />
                                        &nbsp;<input name="lastname" type="text" class="contactRightPanel" size="25" />
                                    </p></td>
                                  </tr>
                                </table>                                
                                <br />
                                Endere&ccedil;o de E-mail*<br />
                                  <input name="emailaddress" type="text" class="contactRightPanel" size="25" />
                                </p>
                                <p>                                  Confirme o Endere&ccedil;o de E-mail*<br />
                                  <input name="emailaddress" type="text" class="contactRightPanel" size="25" />
                                </p>
                                <p>
                                  <input type="submit" value="Submit" name="submit" /></td>
               </tr></table>
              </form>
Post Reply