Jump to content

[SOLVED] web form - different emails per a choice


teanza

Recommended Posts

hey dudes-

 

i posted something a few weex ago, and i finally figured-out my stuff for the most part.

 

however, i need to have my form go 2 a different email per a required drop-down menu selection.  i have the values as 0,1,2,3.  when the form submits, it is only going 2 the top email ("[email protected]") with the corresponding subject, no matter the drop-down selection the user chooses!

 

any ideas? (below) thanx!  :-* :-*

 

 

<?php

if(isset($_POST['email']))

{

switch ($_POST['to']) {

    case 0:

        $to = "[email protected]";

        $subject = "Website Inquiry: A";

        break;

    case 1:

        $to = "[email protected]";

        $subject = "Website Inquiry: B";

        break;

    case 2:

        $to = "[email protected]";

        $subject = "Website Inquiry: C";

        break;

case 3:

        $to = "[email protected]";

        $subject = "Website Inquiry: D";

        break;

}

$body = "*** " . $subject . " *** \n \n";

$body .= "Name: ";

$body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"];

$body .= "\n \n";

$body .= "Phone Number: ";

$body .= $_REQUEST["telephone"];

$body .= "\n \n";

$body .= "Email Address: ";

$body .= $_REQUEST["email"];

$body .= "\n \n";

$body .= "Comments: \n \n";

$body .= $_REQUEST["additionalwords"];

$body .= "\n \n";

$body .= "Complexes: \n \n";

$body .= $_REQUEST["complexes"];

 

$msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>";

 

$msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>";

 

 

$header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n";

 

if (mail($to, $subject, $body, $header)) {

 

  echo $msgSuccess;

} else {

   

  echo $msgError;

}

}

?>

 

 

 

~tina~

Dont no much about switch but try this

 


<?php
if(isset($_POST['email']))
{
switch ($_POST['to']) {
    case "0":
        $to = "[email protected]";
        $subject = "Website Inquiry: A";
        break;
    case"1":
        $to = "[email protected]";
        $subject = "Website Inquiry: B";
        break;
    case "2":
        $to = "[email protected]";
        $subject = "Website Inquiry: C";
        break;
    case "3":
        $to = "[email protected]";
        $subject = "Website Inquiry: D";
        break;
}
$body = "*** " . $subject . " *** \n \n";
$body .= "Name: ";
$body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"];
$body .= "\n \n";
$body .= "Phone Number: ";
$body .= $_REQUEST["telephone"];
$body .= "\n \n";
$body .= "Email Address: ";
$body .= $_REQUEST["email"];
$body .= "\n \n";
$body .= "Comments: \n \n";
$body .= $_REQUEST["additionalwords"];
$body .= "\n \n";
$body .= "Complexes: \n \n";
$body .= $_REQUEST["complexes"];

$msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>";

$msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>";


$header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n";

if (mail($to, $subject, $body, $header)) {

  echo $msgSuccess;
} else {

  echo $msgError;
}
}
{
?>

Tested and worked :-)

 


<?php
  switch ($_POST['to']) {
        case '0':
            $to = "[email protected]";
            $subject = "Website Inquiry: A";
            break;
        case'1':
            $to = "[email protected]";
            $subject = "Website Inquiry: B";
            break;
        case '2':
            $to = "[email protected]";
            $subject = "Website Inquiry: C";
            break;
        case '3':
            $to = "[email protected]";
            $subject = "Website Inquiry: D";
            break;
    }

?>

ok i used the code function this time thanx :D

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact">
            <span id="sprytextfield1">
            <label>
</span><br />
            <br />
        <div align="right"><span><span class="style20"><span class="style21">F</span>irst name</span>
          <input type="text" name="firstname" id="firstname" />
        </span></div>
            <span>
            </label>
            <span class="textfieldRequiredMsg">Kindly enter your first name </span></span><br />
            <br />
<span id="sprytextfield2">
            <label>
            </span>
<div align="right"><span class="style20"><span class="style21">L</span>ast name
  </span>
  <input type="text" name="lastname" id="lastname" />
</div>
<span>
            </label>
            <span class="textfieldRequiredMsg">Kindly enter your last name </span></span>
      <br />
      <br />
      <span id="sprytextfield3">
      <label>
      </span>
      <div align="right"><span class="style20"><span class="style21">E</span>mail address</span>
        <input type="text" name="email" id="email" />
      </div>
      <span>
      </label>
      <span class="textfieldRequiredMsg">Kindly enter your email address </span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
      <br />
      <br />
      <span id="sprytextfield4">
      <label> 
      </span>
      <div align="right"><span class="style20"><span class="style21">P</span>hone number</span>
        <input type="text" name="telephone" id="telephone" />
      </div>
      <span></label><span class="textfieldRequiredMsg">Kindly enter your phone number </span><span class="textfieldInvalidFormatMsg">Invalid format.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span>
      <br />
      <br />
      <span id="spryselect1">
      <label>
      </span>
      <div align="right"><span class="style20"><span class="style21">C</span>omplex of interest</span>
        <select name="complexes" id="complexes">
          <option value="-1" selected="selected">Please choose one</option>
          <option value="0">None/General inquiry</option>
          <option value="1">Seville Square</option>
          <option value="2">Stonehenge</option>
          <option value="3">Logan Road</option>
        </select>
      </div>
      <span>
      </label>
      <span class="selectInvalidMsg">Kindly select a complex </span><span class="selectRequiredMsg">Kindly select a complex </span></span>
      <br />
      <br />
      
      <span>
      <label>
      </label>
      </span>
      <label><div align="right"><span class="style11 style22"><span class="style21">A</span>ny additional comments?</span><span>
          <textarea name="additionalwords" id="additionalwords" cols="45" rows="5"></textarea>
      </span></div>
      </label>
      <span>      <span class="textareaRequiredMsg">A value is required.</span></span><br />
      <label>
      <div align="center">
        <input type="submit" name="submit" id="submit" value="Submit!" />
      </div>
      </label>
      </form>

 

~tina~

Hi,

 

Your drop down field is called "complexes" not "to"

 

here

 

<?php


if(isset($_POST['email']))
{
    switch ($_POST['complexes']) {
        case '0':
            $to = "[email protected]";
            $subject = "Website Inquiry: A";     
            break;
        case'1':
            $to = "[email protected]";
            $subject = "Website Inquiry: B";         
            break;
        case '2':
            $to = "[email protected]";
            $subject = "Website Inquiry: C";     
            break;
        case '3':
            $to = "[email protected]";       
            $subject = "Website Inquiry: D";
            break;
    }
    $body = "*** " . $subject . " *** \n \n";
    $body .= "Name: ";
    $body .= $_REQUEST["firstname"] . " " . $_REQUEST["lastname"];
    $body .= "\n \n";
    $body .= "Phone Number: ";
    $body .= $_REQUEST["telephone"];
    $body .= "\n \n";
    $body .= "Email Address: ";
    $body .= $_REQUEST["email"];
    $body .= "\n \n";
    $body .= "Comments: \n \n";
    $body .= $_REQUEST["additionalwords"];
    $body .= "\n \n";
    $body .= "Complexes: \n \n";
    $body .= $_REQUEST["complexes"];

    $msgError = "<p> <strong>ERROR:</strong>Please re-submit the form; we apologize!</p>";

    $msgSuccess = "<p><strong>Thank you!</strong>We will be in contact shortly by phone or email!</p>";


    $header = "From: ". $_REQUEST["firstname"] . " " . $_REQUEST["lastname"] . " <" . $_REQUEST["email"] . ">\r\n";

if (mail($to, $subject, $body, $header)) {

        echo $msgSuccess;
    } else {

        echo $msgError;
    }
}
?>


u rock my world.  i have very little idea w/what i am doing.  i started out doing a nice basic site, lol.

 

it worked. ur awesome! :D

 

so now that u helped with it, maybe u can tell me how 2 redirect the stupid page? i did it in the meta tag but it keeps jumping back and forth.

 

:D

 

~tina~

Thats great.

 

I personally would have 2 separate files.

 

1 - contactform.html

2 - contactformmailer.php

 

Place all the php code in to contactformmailer.php and change the lines

<?php
if (mail($to, $subject, $body, $header)) {

        echo $msgSuccess;
    } else {

        echo $msgError;
    }
}
?>

 

to


<?php
if (mail($to, $subject, $body, $header)) {

      header("Location:http:YOURSITE.com");
    } 
    else {

        echo $msgError  . "<br /> To go back please click <a href=\"".$_SERVER['HTTP_REFERER']. " \">here</a>";
    }

?>

 

and in the contactform.html

 

change

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact" id="contact">

 

to

<form action="contactformmailer.php" method="post" name="contact" id="contact">

 

well i just need it 2 go 2 the https:// part.  i used a meta tag but it keeps jumping:

 

andrews-management.com

 

i looked-up a php file, but i suppose i failed 2 use it properly!  i need the users to never come across the page without the secure 's'.

 

~tina~

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.