Email Combo

Discussion in 'PHP' started by oo7ml, Jun 18, 2007.

  1. #1
    Hi, i have a contact form, it has a topic field that has certain options as seen below. The form is emailed to , however i want to set it up so that if a user selects the topic as advertising, it emails the form to . I want all the other topics to go to as normal.

    Here is my form: (please note that the small bit of PHP in the code below is used to automatically select the advertising field, incase someone automatically selects the Advertise Here link on the home page)


    <form name="registration" id="Upload" action="contact.processor.php" onSubmit="return validate_form(this);" enctype="multipart/form-data" method="post"> 
              <table width="70%" border="0" cellspacing="1" cellpadding="0">
    		  <tr>
    		  <td colspan="2" valign="bottom"><img src="images/contact.jpg"></td>
    		  </tr>
                <tr bgcolor="#D9D9D8"> 
                  <td width="16%"  class="form">Name:</td>
                  <td width="84%"><input type="text" name="name" size="35" maxlength="30" tabindex="1"></td>
                </tr>
                <tr bgcolor="#D9D9D8"> 
                  <td class="form">Topic:</td>
                  <td>
    			  
    			<?php
    $topic = $_GET['topic']
    ?>
    <select style="width: 185px" name="topic" tabindex="2">
    <option value="null">--- Select Question Type ---</option>
    <option value="Comment or Suggestion">Comment or Suggestion</option>
    <option value="Cancel Membership">Cancel Membership</option>
    <option value="Change Email Address">Change Email Address</option>
    <?php
    if ($topic == 'Advertising') {
         echo '<option value="Advertising" selected="selected">Advertising</option>';
    } else {
         echo '<option value="Advertising">Advertising</option>';
    }
    ?>
    <option value="Press">Press</option>
    <option value="Business Partnerships">Business Partnerships</option>
    <option value="other">- OTHER -</option>
    </select>
    			  
    			  </td>
                </tr>
    			<tr bgcolor="#D9D9D8"> 
                  <td class="form">Mobile:</td>
                  <td><input type="text" name="mobile" size="12" maxlength="10" value="0871234567" onFocus="this.value='';" class="form_small_text_3" tabindex="3">
                  </td>
                </tr>
                <tr bgcolor="#D9D9D8"> 
                  <td class="form">Email:</td>
                  <td><input type="text" name="email" size="32" maxlength="49" tabindex="4">
                  </td>
                </tr>
                <tr bgcolor="#D9D9D8"> 
                  <td class="form">Message:</td>
                  <td colspan="2" class="text"><span class="form_small_text_1">
    			  Please type your message below</span><br> 
    				<textarea tabindex="5" cols="50" rows="8" name="message" class="form_small_text_3" wrap="physical 
    				onKeyDown="textCounter(this.form.message,this.form.remLen,1000);"
    				onKeyUp="textCounter(this.form.message,this.form.remLen,1000); "onFocus="this.value=''; this.onfocus=null;">(Please include a contact number to help us speed up our response)</textarea> 
                    <br>
                    <span class="form_small_text">Characters remaining: 
                    <input readonly type=text name=remLen size=4 maxlength=4 value="1000">
                  </td>
                </tr>
                <tr bgcolor="#D9D9D8"> 
                  <td height="35">&nbsp;</td>
                  <td> <input name="submit" tabindex="6" type="submit" id="submit" value="Send"> 
                    <input type="reset" tabindex="7" name="Reset" value="Reset"></td>
                </tr>
    			<tr>
    		  <td colspan="2"><img src="images/contact_b.jpg"></td>
    		  </tr>
              </table>
    </form>
    HTML:
    Here is the email that is sent

    	 	$todayis 	= date("l, F j, Y, g:i a") ;
    		
    		$name	= $_POST['name']; 
    		$topic	= $_POST['topic'];
    		$mobile	= $_POST['mobile'];
    		$email	= $_POST['email'];
    		$message= $_POST['message'];		
    		$message = stripcslashes($message);
    		
    		$body = " $todayis [EST] \n
    		Name: $name \n
    		Email: $email \n
    		Topic: $topic \n
    		Mobile: $mobile \n
    		
    		Message: $message \n
    		";
    
    $from = "From: $email\r\n";
    
    
    mail("contact@mydomain.ie", $topic, $body, $from);
    PHP:
     
    oo7ml, Jun 18, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Change the last line to:
    if ($topic == 'Advertising')
        $to = "advertising@mydomain.ie";
    else
        $to = "contact@mydomain.ie";
    
    mail($to, $topic, $body, $from);
    PHP:
     
    krt, Jun 18, 2007 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    K cool, thanks a million
     
    oo7ml, Jun 18, 2007 IP
  4. Lemezo

    Lemezo Active Member

    Messages:
    429
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #4
    Just a quick note:You should use divs for the container of the form, and fieldsets to hold every input.
     
    Lemezo, Jun 18, 2007 IP
  5. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #5

    Can you explain what you mean exactly and why, thanks Lemezo
     
    oo7ml, Jun 19, 2007 IP
  6. HuggyCT2

    HuggyCT2 Guest

    Messages:
    222
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    HuggyCT2, Jun 19, 2007 IP