Note that there are some explanatory texts on larger screens.

plurals
  1. POA PHP form that sends emails to different recipients based on options selected
    text
    copied!<p>I am new to php. I am developing a simple contact us form. In that i want to send email to different recipient based on option selected ie. If user select career option then mail should be sent to <code>career@xyz.com</code> &amp; for other than career mail should be sent to <code>other@xyz.com</code>. But i am getting emails on only one email even if the user select different options. Pls help.</p> <p>Below is PHP Code</p> <pre><code>&lt;?php $name = $_POST['name']; $company = $_POST['company']; $email = $_POST['email']; $phone = $_POST['phone']; $country = $_POST['country']; $interested = $_POST['interested']; $message = $_POST['message']; $formcontent="From: $name \n Company Name: $company \n Phone: $phone \n Country Name: $country \n Interested: $interested \n Message: $message"; function emailswitch( $key ) { $to = array( 'Career' =&gt; 'career@xyz.com' ); $default = 'other@xyz.com'; return (!empty($to[$key]))?$to[$key]:$default; } $to = emailswitch( $subject ); $subject = "Enquiry from Website"; $mailheader = "From: $email \r\n"; mail($to, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You! &lt;br /&gt; We will get in touch with you as soon as possible."; ?&gt; </code></pre> <p>HTML is</p> <pre><code>&lt;form name="frm" id="frm" method="POST" action="mail01.php"&gt; &lt;table width="100%" border="0" cellpadding="0" cellspacing="0" class="contact-table"&gt; &lt;tr&gt; &lt;td class="contact-heading"&gt;Send a &lt;span style="color:#171717;"&gt;Message&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td width="43%" rowspan="9" align="center" valign="top" style="padding-top:30px;"&gt;&lt;img src="images/contact-us-new01.jpg" alt="Company Profile"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="43%" align="left" valign="middle"&gt; &lt;div class="contact"&gt;&lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name" id="name" style="width:200px; float:right;" class="validate[required,custom[alphaspace]] for_obj" /&gt;&amp;nbsp; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="43%" align="left" valign="middle"&gt;&lt;div class="contact margin_1line"&gt; &lt;label&gt;Company Name&lt;/label&gt; &lt;input type="text" name="company" id="company" style="width:200px; float:right;" /&gt; &amp;nbsp; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="middle"&gt; &lt;div class="contact margin_1line"&gt;&lt;label&gt;Email&lt;/label&gt; &lt;input type="text" name="email" id="email" style="width:200px; float:right;" class="validate[required,custom[email]] for_obj" /&gt;&amp;nbsp; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="middle"&gt;&lt;div class="contact margin_1line"&gt; &lt;label&gt;Phone&lt;/label&gt; &lt;input type="text" name="phone" id="phone" style="width:200px; float:right;" /&gt; &amp;nbsp; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="middle"&gt; &lt;div class="contact margin_1line"&gt; &lt;label&gt;Country Name&lt;/label&gt; &lt;input type="text" name="country" id="country" style="width:200px; float:right;" class="validate[required,custom[alphaspace]] for_obj" /&gt; &amp;nbsp; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="middle"&gt;&lt;div class="contact margin_1line"&gt; &lt;label&gt;Interested&lt;/label&gt; &lt;select type="text" name="interested" id="interested" style="width:210px; height:28px; border:#dddddd 1px solid; float:right;" class="validate[required,custom[alphaspace]] for_obj"&gt; &lt;option value="Others"&gt;Others&lt;/option&gt; &lt;option value="Product"&gt;Product&lt;/option&gt; &lt;option value="Career"&gt;Career&lt;/option&gt; &lt;option value="Information"&gt;Information&lt;/option&gt; &lt;/select&gt; &amp;nbsp; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="contact margin_1line"&gt;&lt;label for="message"&gt;Message&lt;/label&gt; &lt;textarea name="message" id="message" class="validate[required] for_obj" rows="8" cols="10" style="width:200px; float:right;"&gt;&lt;/textarea&gt;&amp;nbsp; &lt;/div&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left" valign="top" style="padding-left:142px; padding-top:20px;"&gt; &lt;div class="contact"&gt; &lt;label&gt;&amp;nbsp;&lt;/label&gt; &lt;input type="submit" value="Send" class="butt custom_font" /&gt; &lt;input type="reset" value="reset" class="butt custom_font" style=" float:right;" /&gt; &lt;/div&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload