contact form switch error

Dear all,

I’m having problem in my send contact php file. I wanted the email to send based on the subject the visitor choose, for example: Padicure Booking subject the email will send to [email protected] while General Enquiry subject will send to [email protected]

below is my php code.

[php]<?php

function emailswitch() {
$to = array(
‘Pedicure Price Inquiry’ => ‘[email protected]’,
‘Manicure Price Inquiry’ => ‘[email protected]’,
‘Booking Time’ => ‘[email protected]’,
);
$default = ‘[email protected]’;
return isset( $POST['field?’] ) && !empty($to[ $POST['field?’] ]) ? $to[ $POST['field?’] ]: $default; $from = $_POST[‘email’];
}
$from_name = $_POST[‘name’];
$subject = $_POST[‘category’];

// collect data
$body = "";
foreach($_POST as $key => $val)
{
	if($key != 'captcha')
		$body .= ucfirst($key).": ".$val."\r\n";
}

// construct MIME PLAIN Email headers
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=utf-8\n";
$header .= "From: $from_name <$from>\r\nReply-To: $from_name <$from>\r\nReturn-Path: <$from>\r\n";
			
// send email
$mail_sent = mail($to, $subject, $body, $header);	

?>[/php]

below is my form code:

<div id="contact_form"> <form action="sendContact.php" method="post" onsubmit="return sendContact();"> <p><label id="lname" for="name">Full name:</label> <input id="name" class="text" name="name" onblur="input_blur('name');" onfocus="input_focus('name');" type="text" /></p> <p><label id="lemail" for="email">Email address:</label> <input id="email" class="text" name="email" onblur="input_blur('email');" onfocus="input_focus('email');" type="text" /></p> <div class="x"></div> <p id="email-error" class="error">You must enter your email address!</p> <p><label id="lcategory" for="category">Category:</label> <select id="category" name="category" onblur="input_blur('category');" onfocus="input_focus('category');"> <option value="Pedicure Price Inquiry">Pedicure Price Inquiry</option> <option value="Manicure Price Inquiry">Manicure Price Inquiry</option> <option value="Booking Time">Booking Time</option></select></p> <p><label id="lmessage" for="message">Message:</label> <textarea id="message" name="message" onblur="input_blur('message');" onfocus="input_focus('message');" rows="" cols=""></textarea></p> <div class="x"></div> <p id="message-error" class="error">You must enter your message!</p> <p><label id="lcaptcha" for="captcha"></label> <input id="captcha" class="text" name="captcha" onblur="input_blur('captcha');" onfocus="input_focus('captcha');" type="text" /></p> <div class="x"></div> <p id="captcha-error" class="error">Are you sure about your calculations?</p> <script type="text/javascript"> generate_captcha('lcaptcha'); </script> <div class="x"></div> <input class="submit" name="send_contact" type="submit" value="Send" /><input class="submit" type="reset" value="Reset" /> </form> </div> <div id="message_sent" style="display: none;"> <h1>Your message has been sent</h1> <p>We&#39;ll contact you as soon as possible.</p> <p>You can now <a href="./">go back</a> to home page.</p> </div> <!-- end of contact form --></div>

I don’t see a switch anywhere in that code. You’re making that overly complicated. Change

$to = array(‘Pedicure Price Inquiry’ => ‘[email protected]’, ‘Manicure Price Inquiry’ => ‘[email protected]’,
‘Booking Time’ => ‘[email protected]’,);

To
[php]
function emailswitch($to) {
if($to == “Pedicure Price Inquiry”) {
$address = "[email protected]";
} elseif($to == “Manicure Price Inquiry”) {
$address = "[email protected]";
} elseif($to == “Booking Time”) {
$address = "[email protected]";
} else {
$address = "[email protected]";
}
return $address;
}

$sendto = emailswitch($_POST[‘lcatagory’]);[/php]

by the way the code not working thou…

below is my updated code

[php]<?php

function emailswitch($to) {
if($to == “Pedicure Price Inquiry”) {
$address = "[email protected]";
} elseif($to == “Manicure Price Inquiry”) {
$address = "[email protected]";
} elseif($to == “Booking Time”) {
$address = "[email protected]";
} else {
$address = "[email protected]";
}
return $address;
}

$sendto = emailswitch($_POST[‘lcategory’]);
$from_name = $_POST[‘name’];
$email = $_POST[‘email’];
$subject = $_POST[‘subject’];

// collect data
$body = "";
foreach($_POST as $key => $val)
{
	if($key != 'captcha')
		$body .= ucfirst($key).": ".$val."\r\n";
}

// construct MIME PLAIN Email headers
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/plain; charset=utf-8\n";
$header .= "From: $from_name <$email> \r\nReply-To: $from_name <$email> \r\nReturn-Path: <$email> \r\n";
			
// send email
$to = emailswitch( $subject );
$mail_sent = mail($to, $subject, $body, $header);

?>[/php]

my html

<div id="contact_form"> <form action="sendContact.php" method="post" onsubmit="return sendContact();"> <p><label id="lname" for="name">Full name:</label> <input id="name" class="text" name="name" onblur="input_blur('name');" onfocus="input_focus('name');" type="text" /></p> <p><label id="lemail" for="email">Email address:</label> <input id="email" class="text" name="email" onblur="input_blur('email');" onfocus="input_focus('email');" type="text" /></p> <div class="x"></div> <p id="email-error" class="error">You must enter your email address!</p> <p><label id="lsubject" for="subject">Subject:</label> <select id="subject" name="subject" onblur="input_blur('subject');" onfocus="input_focus('subject');"> <option value="Pedicure Price Inquiry">Pedicure Price Inquiry</option> <option value="Manicure Price Inquiry">Manicure Price Inquiry</option> <option value="Booking Time">Booking Time</option></select></p> <p><label id="lmessage" for="message">Message:</label> <textarea id="message" name="message" onblur="input_blur('message');" onfocus="input_focus('message');" rows="" cols=""></textarea></p> <div class="x"></div> <p id="message-error" class="error">You must enter your message!</p> <p><label id="lcaptcha" for="captcha"></label> <input id="captcha" class="text" name="captcha" onblur="input_blur('captcha');" onfocus="input_focus('captcha');" type="text" /></p> <div class="x"></div> <p id="captcha-error" class="error">Are you sure about your calculations?</p> <script type="text/javascript"> generate_captcha('lcaptcha'); </script> <div class="x"></div> <input class="submit" name="send_contact" type="submit" value="Send" /><input class="submit" type="reset" value="Reset" /> </form> </div> <div id="message_sent" style="display: none;"> <h1>Your message has been sent</h1> <p>We&#39;ll contact you as soon as possible.</p> <p>You can now <a href="./">go back</a> to home page.</p> </div> <!-- end of contact form --></div>

my mistake, change emailswitch($_POST[‘lcatagory’] to emailswitch($_POST(‘category’);

Sponsor our Newsletter | Privacy Policy | Terms of Service