Jump to content

Recommended Posts

Hey,

 

I have a fairly simple script that allows users to fill in their email, then the message then submit the form and it submits to an email address...What Ive added now is a drop down menu that allows users to select which department they want their email to go to. Iam unsure how to code the sendmail.php (the script that actually sends the email)

 

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "[email protected]", "REQUEST",
    $message, "From: $email" );
  header( "Location: http://www.mysite.com/thankyou.html" );
?>

 

That is just how it appears now, Im trying to configure it for the drop down I added, Ill be re-searching this but any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/116847-code-check/
Share on other sites

Use the HTML:

<select name="department">
<option value="Sales">Sales</option>
<option value="Marketing">Marketing</option>
<option value="Support">Support</option>
</select>

 

Then add to your PHP something like:

 

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
  $department = $_REQUEST['department'];

  if($department == 'Sales')
  {
$sendto = '[email protected]';
  }
  elseif($department == 'Marketing')
  {
$sendto = '[email protected]';
  }
  elseif($department == 'Support')
  {
$sendto = '[email protected]';
  }

  mail( $sendto, "REQUEST",
    $message, "From: $email" );
  header( "Location: http://www.mysite.com/thankyou.html" );
?>

Link to comment
https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600872
Share on other sites

Instead of that big condition statement that you will have to keep adding to as departments are added, just do this:

$department = $_REQUEST['department'];
$allowed = array('sales','marketing','support'); // add more departments here
// change [email protected] to default email address
$sendto = (in_array($department, $allowed))? $department . "@yoursite.com" : "[email protected]";

Link to comment
https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600876
Share on other sites

One last question (sorry!)

 

When a user selects a department and fills out his message and then clicks 'submit' if I want to submit the email (only for that specific department) to three email addresses would I do this:

 

$sendto = '[email protected]; [email protected]; [email protected]';

 

or

 

$sendto = '[email protected]' '[email protected]' '[email protected]';

 

I tried both ways and it doesn't seem to be submitting to any of the three email addresses

Link to comment
https://forums.phpfreaks.com/topic/116847-code-check/#findComment-600906
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.