SuperWebman Posted May 25, 2011 Share Posted May 25, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/ Share on other sites More sharing options...
zer0day Posted May 25, 2011 Share Posted May 25, 2011 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220277 Share on other sites More sharing options...
Drummin Posted May 25, 2011 Share Posted May 25, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220278 Share on other sites More sharing options...
SuperWebman Posted May 25, 2011 Author Share Posted May 25, 2011 hmm ok that does work for it to go to the thank you page after submitting, but it is still not email anything. Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220293 Share on other sites More sharing options...
Drummin Posted May 25, 2011 Share Posted May 25, 2011 Then I would get rid of $success = ... as I assumed you were using it somewhere else. Just use mail($wm, $emailSubject, $body, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220294 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 Ok looks like everything is working except its not displaying the address in the email. Everything else displays good. What do you think? Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220351 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 wait i think i figured it out where it shows the body it was still $Address and since you changed everything to $add that might not work. so changed that and sent form. Waiting to see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220354 Share on other sites More sharing options...
Drummin Posted May 26, 2011 Share Posted May 26, 2011 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; } Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220356 Share on other sites More sharing options...
jcbones Posted May 26, 2011 Share Posted May 26, 2011 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"; Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220357 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 i'm not following you there sorry i'm pretty new at this still. Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220360 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220365 Share on other sites More sharing options...
Drummin Posted May 26, 2011 Share Posted May 26, 2011 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". Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220368 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220370 Share on other sites More sharing options...
Drummin Posted May 26, 2011 Share Posted May 26, 2011 Wonderful it's working for you! Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220383 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 Yup it is only prob I have is if someone doesn't fill out all fields of form it will go to a white page when submitted and won't email. so I need to do some validation script to prevent that . any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220387 Share on other sites More sharing options...
SuperWebman Posted May 26, 2011 Author Share Posted May 26, 2011 well thank you guys for helping me. And....I actually learned something today lol. Which is always good Quote Link to comment https://forums.phpfreaks.com/topic/237470-php-mailing-form-not-working-doh/#findComment-1220416 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.