Jump to content

contact form sent to different emails


harshadmethrath

Recommended Posts

Hi heres the form to take a look http://jamaicainn.com/contact.php

 

the contact form basically is now sending all the information to the database of our external partner. I have a field "Regarding" which when selected the form information goes to the respected departments for ex., Spa goes to spa@jamaicainn.com

 

heres the code I wrote. which doesnt seem to work

 

<?php
if ($regarding == 'Human Resources'){
    // form action email(sophiaw@jamaicainn.com, $subject, $message) then redirect to
}  elseif ($regarding == 'Guest Relations'){
    // form action email(shickling@jamaicainn.com@jamaicainn.com, $subject, $message)
} elseif ($regarding == 'Spa'){
    // form action email(spa@jamaicainn.com, $subject, $message)
} elseif ($regarding == 'Marketing'){
    // form action email(tina@jamaicainn.com, $subject, $message)
}elseif ($regarding == 'Accounts'){
    // form action email(debra.freak@jamaicainn.com, $subject, $message)
}  elseif ($regarding == 'Reservations') {
     // form action post(http://www.NavisTechnologies.info/Narrowcast2005/ELM/ELMContactPost.aspx)
}
?>


<p><form name="form1" method="post" action="http://www.NavisTechnologies.info/Narrowcast2005/ELM/ELMContactPost.aspx">
            <table width="90%" border="0" cellpadding="3" cellspacing="3">
              <tr>
                <td width="30%"> <input name="account" value="15340" type="hidden" />
      <label for="FirstName">First name*</label></td>
                <td><input type="text" name="FirstName" id="FirstName" required></td>
              </tr>
              <tr>
                <td><label for="LastName">Last name*</label></td>
                <td><input type="text" name="LastName" id="LastName" required></td>
              </tr>
              <tr>
                <td><label for="EmailAddress">Email*</label></td>
                <td><input type="email" name="EmailAddress" id="EmailAddress" required></td>
              </tr>
              <tr>
                <td><label for="HomePhone">Phone</label></td>
                <td><input type="tel" name="HomePhone" id="HomePhone"></td>
              </tr>
              <tr>
                <td><label for="regarding">Regarding</label></td>
                <td><select name="regarding" id="regarding">
                 <option><p> Reservations</p></option>
                 <option><p> Guest Relations</p></option>
                 <option><p> Spa</p></option>
                 <option><p> Marketing</p></option>
                 <option><p> Human Resources</p></option>
                 <option><p> Accounts</p></option>
                 <option><p> Groups/Weddings</p></option>
                </select></td>
              </tr>
              <tr>
                <td><label for="CheckInDate">Check in date</label></td>
                <td><input name="CheckInDate" type="Date" id="CheckInDate"><a href="javascript:openCalendar('CheckInDate')"><img src="http://jamaicainn.com/calendar.gif" width="20" height="20" border="0" /></a></td>
              </tr>
              <tr>
                <td><label for="CheckOutDate">Check out date</label></td>
                <td><input name="CheckOutDate" type="Date" id="CheckOutDate"><a href="javascript:openCalendar('CheckOutDate')"><img src="http://jamaicainn.com/calendar.gif" width="20" height="20" border="0" /></a></td>
              </tr>
              <tr>
                <td><label for="Date">Comments</label></td>
                <td><textarea name="Message" id="Message" cols="30" rows="4"></textarea></td>
              </tr>
              <tr>
                <td> </td>
                <td><input name="send" type="submit" class="submit" id="send" value="SUBMIT"></td>
              </tr>
            </table>
          </form>
  
        <script language="javascript" type="text/javascript">
function openCalendar(FormElement){
    var calendarwindow;
    url = "calendar.html?formname=form1&formelement=" + FormElement;
    calendarwindow = window.open(url,"calendar","toolbar=no,width=200,height=144,top=50,left=50,status=no,scrollbars=no,resize=no,menubar=no");
    calendarwindow.focus();
}
</script>

 

Any helps appreciated

 

Thanks

Link to comment
Share on other sites

Change all this redundant code:

if ($regarding == 'Human Resources'){
// form action email(sophiaw@jamaicainn.com, $subject, $message) then redirect to
} elseif ($regarding == 'Guest Relations'){
// form action email(shickling@jamaicainn.com@jamaicainn.com, $subject, $message)
} elseif ($regarding == 'Spa'){

 

to something more logical:

if ($regarding == 'Human Resources')
$to = "sophiaw@jamaicainn.com";
elseif ($regarding == 'Guest Relations')
$to = "shickling@jamaicainn.com";
elseif ($regarding == 'Spa')
...

 

Then simply get your subject and message and headers setup into their variables and send your mail using the to you create above. One mail call.

Edited by ginerjm
  • Like 1
Link to comment
Share on other sites

If you liked that you should read the manual for the switch statement usage. Even easier to setup.

 

PS - I don't think you need the p tags inside your option tags. Kind of doesn't make sense to add extra html levels to a simple list element which the option tag really is.

Link to comment
Share on other sites

Your code made me nostalgic for all things '90s, and I didn't feel like cleaning the house yet, so I knocked up a slightly more modern version. It's completely untested so don't expect to copy and paste it, but hopefully it'll put you on the right track. Also, don't quote me on the JavaScript validation - the concept is valid, but the syntax might be a bit wonky.

<!html>
<head>
	<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
	<script src="//code.jquery.com/jquery-1.10.2.js"></script>
	<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<?php
$message = '';
$addresses = array(
	'hr'	=> 'hr@youremail',
	'gr'	=> 'gr@youremail',
	'spa'	=> 'spa@youremail.com',
	'mkt'	=> 'marketing@youremail.com',
	'acct'	=> 'accounts@youremail.com',
	'reso'	=> 'reservations@youremail.com',
	'event'	=> 'events@youremail.com',
);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	$message = mailIt($addresses, $_POST['regarding'], $_POST );
}
/**
 *	See https://github.com/PHPMailer/PHPMailer for documentation.
 *	Remember you'll need to validate and sanitize all the user-submitted data.
 *	I didn't do that in this example...
 *
 *	@param	array	$addys		Array of possible email addresses
 *	@param	string	$reg		The user-selected email address to send to
 *	@param	array	$fields		User-submitted form field values
 *	@return	string
 */
function mailIt(array $addys, $reg='hr', array $fields){
	$mail = new PHPMailer();
//set up your configuration according to the PHPMailer documentation here
	$mail->setAddress($addys[$reg]);
	$mail->setFrom('contact@youremail.com');
	$mail->Subject = 'Contact form filled out';
	$mail->Body = '';// Build the body of the email from the $fields array
	if($mail->send()){
		return "Your mail has been sent. Thank you!";
	}else{
		return "Sorry! There was an error. Please try again";
	}
}
?>

	<form name='contact' method='post' id='contact' class='form contact'>
		<div class='response'><?= $message; ?></div>
		<fieldset>
			<label for='firstName'>First Name*</label>
			<input type='text' name='firstName' id='firstName' data-req='required' />
		</fieldset>
		<fieldset>
			<label for='lastName'>Last Name*</label>
			<input type='text' name='lastName' id='lastName' data-req='required' />
		</fieldset>
		<fieldset>
			<label for='eAddy'>Email Address*</label>
			<input type='text' name='eAddy' id='eAddy' data-req='required' />
		</fieldset>
		<fieldset>
			<label for='phone'>Phone*</label>
			<input type='text' name='phone' id='phone' data-req='required' />
		</fieldset>
		<fieldset>
			<label for='regarding'>Regarding</label>
			<select name='regarding' id='regarding'>
				<option value='reso'>Reservations</option>
				<option value='gr'>Guest Relations</option>
				<option value='spa'>Spa</option>
				<option value='mkt'>Marketing</option>
				<option value='hr'>Human Resources</option>
				<option value='acct'>Accounts</option>
				<option value='event'>Groups/Weddings</option>
			</select>
		</fieldset>
		<fieldset>
			<label for='checkInDate'>Check In Date</label>
			<input type='text' id='checkInDate' class='datePicker' name='checkInDate' />
		</fieldset>
		<fieldset>
			<label for='checkOutDate'>Check Out Date</label>
			<input type='text' id='checkOutDate' class='datePicker' name='checkOutDate' />
		</fieldset>
		<fieldset>
			<label for='comments'>Comments</label>
			<textarea id='comments' name='comments'></textarea>
		</fieldset>
		<input type='submit' value='SUBMIT' name='submit' class='submit' />
	</form>
</body>

<script language="javascript" type="text/javascript">
	$('.datePicker').datepicker('option','format','d MM, yy');
	$('#submit').click(function(){
		$('#contact input').each(function(){
			if($(this).attr('data-req').val() == 'required'){
				if($(this).val() === ''){
					alert('Please fill out all required fields');
					return false;
				}
			}
			return true;
		});
	});
</script>
</html>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.