Jump to content

Recommended Posts

Hey everyone I'm pretty new at PHP so i'm hoping someone can help me with this code. What I am trying to do is if someone selects a state say Kansas then fills out the rest of the form and clicks submit it will go to a specific email address. If someone selects another state like Nebraska it will go to a separate email address. Here is my code and I hope someone can help me with this.

 

PS I think I really screwed this one up lol :help:

 

Thanks,

 

B

<?php

/* Subject and Email variables */

$emailSubject = 'Your Car Report Info.';
$webMaster = 'me@rustyeckford.com';
$webMaster2 ='me1@rustyeckford.com';
$webMaster3 ='me2@rustyeckford.com';

/* Gathering Data Variables */

$f_nameField = $_POST['f_name'];
$l_nameField = $_POST['l_name'];
$addField = $_POST['Address'];
$stateField = $_POST['state'];
$phoneField = $_POST['phone'];
$emailField = $_POST['email'];
$vinField = $_POST['vin'];

$body = <<<EOD
<br><hr><br>
First Name: $f_name <br>
Last Name: $l_name <br>
Address: $Address <br>
State: $state <br>
Phone: $phone <br>
Email: $email <br>
VIN: $vin <br>
EOD; 

switch($state) {
  case 'Kansas':
  case 'Oklahoma':
    $wm = $webMaster2;
    break;
  case 'Missouri':
  case 'Iowa':
    $wm = $webMaster3;
    break'
  case 'Nebraska:
    $wm = $webMaster;
    break;
}  

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($wm, $emailSubject, $body, $headers);

/* Results rendered from Html */

$theResults = <<<EOD
<html>
<head>
<title>Your Car Report - Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">

body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}

</style>
</head>

<div>
  <div align="center">Thank you for your submission. Your vehicle report will be provided to you very soon!</div>
</div>
</body>
</html>
EOD;



echo "$theResults";
  

?>

Link to comment
https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/
Share on other sites

I took your code and added/subtracted a few things, although I didn't fix much -- I just got it to the point where it should work, so if there were errors in your initial code, they're still there.  Here ya go:

 

<?php

/* Subject and Email variables */

$emailSubject = "Your Car Report Info.";
$webMaster = "me@rustyeckford.com";
$webMaster2 ="me1@rustyeckford.com";
$webMaster3 ="me2@rustyeckford.com";

/* Gathering Data Variables */

$f_nameField = $_POST['f_name'];
$l_nameField = $_POST['l_name'];
$addField = $_POST['Address'];
$stateField = $_POST['state'];
$phoneField = $_POST['phone'];
$emailField = $_POST['email'];
$vinField = $_POST['vin'];

$body = "<br><hr><br>"."First Name: ".$f_name."<br />";
$body .= "Last Name: ".$l_name."<br />";
$body .= "Address: ".$address."<br />";
$body .= "State: ".$state."<br />";
$body .= "Phone: ".$phone."<br />";
$body .= "Email: ".$email."<br />";
$body .= "VIN: ".$vin."<br />";

switch($state) {
case 'Kansas':
case 'Oklahoma':
	$wm = $webMaster2;
    	break;
case 'Missouri':
	break;
case 'Iowa':
    	$wm = $webMaster3;
    	break;
    case 'Nebraska':
    	$wm = $webMaster;
    	break;
    default:
    	$wm = $webMaster;
}  

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($wm, $emailSubject, $body, $headers);

$theResults = "<html><head><title>Your Car Report - Results</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><style type=\"text/css\">";
$theResults .= "
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
";
$theResults .= "</style></head><div><div align=\"center\">Thank you for your submission. Your vehicle report will be provided to you very soon!</div></div></body></html>";

echo $theResults;

?>

You REALLY need to validate your input! There are were errors in your switch.  In any case, see if this works. 

<?php

/* Subject and Email variables */

$emailSubject = 'Your Car Report Info.';
$webMaster = 'me@rustyeckford.com';
$webMaster2 ='me1@rustyeckford.com';
$webMaster3 ='me2@rustyeckford.com';

/* Gathering Data Variables */
IF ($_POST){ 
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$add = $_POST['Address'];
$state = $_POST['state'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$vin = $_POST['vin'];
  
}//END IF POST
//********VALIDATE POST!!!!!!******//
//if values are good//
IF ((!empty($f_name)) && (!empty($l_name)) && (!empty($add)) && (!empty($state)) && (!empty($phone)) && (!empty($email)) && (!empty($vin))){

$body = "<br><hr><br>First Name: $f_name <br>Last Name: $l_name <br>Address: $Address <br>State: $state <br>Phone: $phone <br>Email: $email <br>VIN: $vin<br>"; 

switch($state) {
  case 'Kansas';
  case 'Oklahoma';
    $wm = $webMaster2;
    break;
  case 'Missouri';
  case 'Iowa';
    $wm = $webMaster3;
    break;
  case 'Nebraska';
    $wm = $webMaster;
    break;
}
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($wm, $emailSubject, $body, $headers);

/* Results rendered from Html */

?>
<html>
<head>
<title>Your Car Report - Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">

body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}

</style>
</head>
<div>
  <div align="center">Thank you for your submission. Your vehicle report will be provided to you very soon!</div>
</div>
</body>
</html>
<?PHP
}
?>

Looks like I used semi-colons instead of colons in the switch.  I don't use switches much, sorry about that.  I think it should be

switch($state) {
  case 'Kansas':
  case 'Oklahoma':
    $wm = $webMaster2;
    break;
  case 'Missouri':
  case 'Iowa':
    $wm = $webMaster3;
    break;
  case 'Nebraska':
    $wm = $webMaster;
    break;
}

There should really be a sticky about emails not sending.  The number UNO (1) problem faced is that in today's interweb consortium games, most every HOST on the market REQUIRES that the FROM header on emails match an EXISTING email account hosted on the SMTP (email) server.

 

Short form:

You cannot use a submitted email to SEND the email, you must change:

$headers = "From: $email\r\n";

To a valid email that exist on your server.  You can still put that email in the body of the message.

 

IE:

$headers = "From: me@rustyeckford.com\r\n";

cool it worked without changing the From: $email.  now the only thing that I need to do is make is so that the person has to fill out all of the textboxes.  because if they don't it doensn't work.  it will go to the next page the thank you one, but instead of having the thank you it is blank. oh BTW Drummin I didn't have to change the semicolons

 

What he's saying is that you should setup email accounts with your host for me@rustyeckford.com,

me1@rustyeckford.com and me2@rustyeckford.com. 

 

My host allows mail() along with SMTP.

 

My hosting does require this as well, so if your domain is rustyeckford.com you should be able to add an address for "me", "me1" and "me2".

well all of the emails are actually going to 3 of our dealerships.  so they are name@midwestsuperstore.com, name@rustyeckfordomaha.com, and finally name@rollinghillsautoplaza.com.  But it seemed to work they way it is and I am getting all of the form info. 

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.