Email Combo

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
oo7ml
Forum Newbie
Posts: 15
Joined: Sun Jun 17, 2007 4:30 pm

Email Combo

Post by oo7ml »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi, i have a contact form, it has a topic field that has certain options as seen below. The form is emailed to [email]contact@mydomain.com[/email], however i want to set it up so that if a user selects the topic as advertising, it emails the form to [email]advertising@mydomain.com[/email]. I want all the other topics to go to [email]contact@mydomain.com[/email] 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)

Code: Select all

<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>
Here is the email that is sent

Code: Select all

$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);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
oo7ml
Forum Newbie
Posts: 15
Joined: Sun Jun 17, 2007 4:30 pm

Post by oo7ml »

sorted thanks

Code: Select all

if ($topic == 'Advertising')
    $to = "advertising@mydomain.ie";
else
    $to = "contact@mydomain.ie";

mail($to, $topic, $body, $from);
Post Reply