7 Replies - 13502 Views - Last Post: 27 April 2011 - 07:45 PM Rate Topic: -----

#1 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

sending email php with Dropdown for email

Posted 27 April 2011 - 02:01 PM

I'm having issues remembering how to make a "process" form for sending emails. I have the contact form already but I am using a dropdown for the departments. I have never set it up this way. I have been searching for a solution on how to send an email to the department in the list. my current contact form look like this:

<body>
<table width="100%" border="0" cellpadding="5" cellspacing="10" bgcolor="#ffffff">
  <tr>
    <td colspan="2" align="center" class="aboutUs"><h1>Contact Us</h1>
      <h4>Questions or Comments? <br />
      You can contact Any of ****** departments by using the form below.</h4>
    <hr color="#900000" /></td>
  </tr>
  	<tr>
    	<td colspan="2" >
       
        	<h4 class="eventhead"><strong>Please fill in all information so we can contact you back. If you would like a call back, please enter that into comments section with the best time to call you.<br />
       	    Thank you!
       </strong></span></span></h4></td>
    </tr>
    <tr>
        <td width="30%" align='center'>
        
        <td width="70%" align='left'> 
           <form action='index.php' method='post'>
        	<p>Name:
              
              <input type='text' size'50' name='name' />
      	  </p>
       	  <p>
            Email: 
            <input type='text' size='50' name='email' />
           <p>	
           		Dept:  
           		
   		     <select name='dropdown' >
             	  <option name=''>Please Choose Dept.</option>
	       		  <option name='boating@******.com'>Boating</option>
       		      <option name='camping@******.com'>Camping</option>
       		      <option name='fishing@******.com'>Fishing</option>
       		      <option name='general@******.com'>General</option>
       		      <option name='guns@******.com'>Guns</option>
       		      <option name'hunting@******.com'>Hunting</option>
       		      <option name='sales@******.com'>Sales</option>
       		      <option name='site@******.com'>Site Management</option>
       		      <option name='toys@******.com'>Toys</option>
	         </select>
             <p>Subject:
   		   <input type='text' size='50' name='subject' />
           <p>Comments/Suggestions:<br />
             <textarea rows='10' cols='50' name='comment'></textarea>
          <p>
            <input type="submit" value="Send">
              
            <input type="hidden" name="content" value="sendemail">
              
  </form>      
    <tr>
      <td colspan="2" align='center'>   
      <hr color="#900000" />   
      </td>
   </tr> 
  </table>



I'm using tables since the person who is going to be managing this isn't CSS savvy so please don't comment on that, I would rather use div tags, sorry.

The select/options section is the main issue. I haven't created the sendemail yet, I was going to do that once I can figure out the array part or if I even need an array.

My Q is how would I go about setting the $sendto to the email in the list? Do I need to make it an array or can I just have them select from the drop down and assign it to $sendto in the sendemail page?

Any suggestions would be greatly appreciated!!

This post has been edited by laehm: 27 April 2011 - 02:05 PM


Is This A Good Question/Topic? 0
  • +

Replies To: sending email php with Dropdown for email

#2 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:07 PM

It would be a simple form submission i would presume ...

if your form method is POST

$_POST['dropdown']



would provide the data that the dropdown menu was set to

if using GET

$_GET['dropdown']



the main issue with this is i see no form declaration in your HTML ... well not a opening one anyways i see you closed a form there.
Was This Post Helpful? 0
  • +
  • -

#3 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:25 PM

Form opening is on line 20. I thought about just doing the get dropdown but am continuously second guessing myself. I will go ahead with that and see if it works, hopefully it does!!

Thank you!!
Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:28 PM

Ah i completely overlooked your form opening.

It is set to POST though so you would not be using using GET
Was This Post Helpful? 0
  • +
  • -

#5 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:28 PM

Set a value field.

This approach is very vulnerable to exploits. Someone could simply use cURL to send automated request to your mail script and set 'dropdown' to anything they want.

I'd suggest setting the values to Boating, Camping, Fishing,.... then in your PHP script read the emails from an associative array.

<select name='dropdown' >
  <option value=''>Please Choose Dept.</option>
  <option value='boating'>Boating</option>
  <option value='camping'>Camping</option>
  <option value='fishing'>Fishing</option>
  ...
</select>



//PHP
$emails = array('boating' => 'boating@xxxxxx.xxx', 'camping' => 'camping@xxxxxx.xxx'); //u get the point
if(array_key_exists($_POST['dropdown']))
{
	$recipient = $emails[$_POST['dropdown']];
	//send email to $recipient
}

Was This Post Helpful? 1
  • +
  • -

#6 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:36 PM

Ah-ha! that is very smart Codeprada! I didn't even think of that. That, in turn, is more efficient and simplifies what I am trying to do. Another reason to why I was second guessing and thinking of arrays.

Wow thank you! :D :clap:
Was This Post Helpful? 0
  • +
  • -

#7 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 02:55 PM

Also one last thing...

If you're using PHP's mail function be sure to protect it against email header injection attacks. I've seen way too many people sending mail using variables directly from POST or GET requests to send mail. Click here to view tutorial.

Cheers
Was This Post Helpful? 0
  • +
  • -

#8 laehm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 20-May 10

Re: sending email php with Dropdown for email

Posted 27 April 2011 - 07:45 PM

Yes, I remembered that but haven't added it in yet, Thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1