Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

PHP mailing form


(!)

SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
24-May-2011, 03:14 PM #1
Question PHP mailing form
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.

Thanks,

B

<?php

/* Subject and Email variables */

$emailSubject = 'Crazy PHP Scripting';
$webMaster = 'something@something2.com';
$webMaster2 ='something@something.com';
$webMaster3 ='something@something1.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;

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

$success = mail($webMaster, $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";


?>
ehymel's Avatar
ehymel   (Ernie) ehymel is offline
Member with 695 posts.
 
Join Date: Aug 2007
Location: Texas
24-May-2011, 07:50 PM #2
Lots of options, but one good option would be the php switch statement.

PHP Code:
switch($state) {
  case 
'AL':
    
$wm $webMaster;
    break;
  case 
'TX':
  case 
'LA':
    
$wm $webMaster2;
    break
'
  case '
WA':
    $wm = $webMaster3;
    break;

See the php.net documentation (linked above) for several more examples.
ehymel's Avatar
ehymel   (Ernie) ehymel is offline
Member with 695 posts.
 
Join Date: Aug 2007
Location: Texas
25-May-2011, 10:54 AM #3
Per your private message to me, I've inserted my suggestion into your code, then modified the email command to match the variable I used for the email address. You will of course have to modify my suggestion to meet your specifics.

I don't mind the private message, but when it's related to a post like this then let's keep the discussion within the thread so that others can find this in the future and benefit if they have the same question.

PHP Code:
<?php

/* Subject and Email variables */

 
$emailSubject 'Crazy PHP Scripting';
 
$webMaster 'something@something2.com';
 
$webMaster2 ='something@something.com';
 
$webMaster3 ='something@something1.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 'AL':
    
$wm = $webMaster;
    break;
  case 'TX':
  case 'LA':
    
$wm = $webMaster2;
    break'
  case 'WA:
    
$wm = $webMaster3;
    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";
  
 
?>
Hope this helps!
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 10:56 AM #4
Ha ha that's funny because I did this while I was waiting for you to answer.

<?php

/* Subject and Email variables */

$emailSubject = 'Crazy PHP Scripting';
$webMaster = 'djuelfs@rustyeckfordomaha.com';
$webMaster2 ='keithz@midwestsuperstore.com';
$webMaster3 ='delder@rollinghillsautoplaza.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':
$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($webMaster, $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";


?>
ehymel's Avatar
ehymel   (Ernie) ehymel is offline
Member with 695 posts.
 
Join Date: Aug 2007
Location: Texas
25-May-2011, 11:56 AM #5
Excellent. You still have to change your email command. Change from what you have currently:

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

To this:
$success = mail($wm, $emailSubject, $body, $headers);
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 02:57 PM #6
hmm well for some reason this isn't working. I'm not sure why, but it won't email out. I was on the phone with godaddy because I was setting up the hosting and had to set up the automated email so that the server wouldn't think it was spam. But i'm not sure if there is something wrong with the code or not.
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 09:12 PM #7
I figured it out. the only thing I need to do now is somehow make it so that they have to fill the form entirely otherwise it says you didn't fill the form out completely and it won't submit until they have done so.
ehymel's Avatar
ehymel   (Ernie) ehymel is offline
Member with 695 posts.
 
Join Date: Aug 2007
Location: Texas
25-May-2011, 09:14 PM #8
Quote:
Originally Posted by SuperWebman View Post
I figured it out. the only thing I need to do now is somehow make it so that they have to fill the form entirely otherwise it says you didn't fill the form out completely and it won't submit until they have done so.
Excellent. Please mark your thread as solved.

The form validation (as you have described your needs) is best done on the client side with something like javascript.

Good luck!
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 09:25 PM #9
hmmm on to the javascript forum lol

I really appreciate your help
ehymel's Avatar
ehymel   (Ernie) ehymel is offline
Member with 695 posts.
 
Join Date: Aug 2007
Location: Texas
25-May-2011, 09:26 PM #10
It's not that hard actually... give it a shot and post any questions here!
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 09:26 PM #11
ok I will thanks
SuperWebman's Avatar
SuperWebman SuperWebman is offline
Junior Member with 11 posts.
THREAD STARTER
 
Join Date: May 2011
Experience: Advanced
25-May-2011, 09:48 PM #12
Well I tried it. It's not really working when I upload it to the server.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="file:///C|/Users/bschomp/Desktop/style.css" rel="stylesheet" type="text/css" media="screen" />
<title>Your Car Report | Kansas Vehicles | Nebraska Autos | Missouri Title Info | Iowa Car </title>



<style type="text/css">
body {
	background-image: url(images/images/bluebg.jpg);
}
#header {
	background-color: #CCC;
	height: 500px;
	width: 600px;
	margin-top: 0px;
	margin-right: 500px;
	margin-bottom: 800px;
	margin-left: 501px;
}
#LOGO {
	height: 98px;
	width: 232px;
	margin-top: 200px;
	margin-bottom: 0px;
	margin-right: 0px;
	float: left;
	background-color: transparent;
}
#background {
	background-color: transparent;
	margin:
	height: 900px;
	width: 1400px;
}
#leftsidebar {
	background-color: transparent;
	height: 600px;
	width: 1400px;
	margin-top: 200px;
	margin-right: 500px;
	margin-bottom: 0px;
	margin-left: 0px;
	padding-left: 125px;
}
#leftfloat {
	margin: 0px;
	float: left;
	height: 590px;
	width: 300px;
}
#middlefloat {
	float: left;
	margin: 0px;
	height: 500px;
	width: 700px;
	background-color: #fff;
}
#background {
}
#logo {
	float: right;
	height: 98px;
	width: 232px;
	padding-right: 20px;
}
#middle {
	margin: auto;
	height: 465px;
	width: 650px;
	margin-top: 20px;
	background-color: #657489;
	background-image: url(images/images/mediumbkgd.png);
}
#about {
	background-color: transparent;
	margin: 0px;
	float: right;
	height: 488px;
	width: 250px;
	padding-right: 20px;
	padding-top: 50px;
}
#rightinfo {
	margin: 0px;
	float: left;
	height: 360px;
	width: 309px;
}
</style>
</head>

<body>
<div id="background">
  <div id="leftsidebar">     
    <div id="leftfloat">
      <div id="logo"><img src="images/images/logo.png" width="232" height="98" /></div>
      
<div id="about"><img src="images/images/sidebar.png" width="245" height="487" /></div>
 </div>
    
    <div id="middlefloat">
      <div id="middle">
        <form id="form1" name="form1" method="post" action="contactforprocess.php">
          <p>
            <label for="f_name"><br />
              <br />
              <br />
              <br />
              <br />
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;First Name&nbsp;</label>
            <input type="text" size="25" name="f_name" id="f_name" />
            &nbsp;&nbsp;
<label for="l_name">Last Name&nbsp;&nbsp;</label>
            <input type="text" name="l_name" size="25"id="l_name" />
          </p>
          <p>
          &nbsp;&nbsp;&nbsp;&nbsp;</p>
          <p> <label for="Address">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Address&nbsp;&nbsp;</label>
            <input type="text" name="add" size="45" id="add" />
            <label for="state">  &nbsp;&nbsp;&nbsp;&nbsp;State</label>
            <select name="state" id="state">
              <option>Choose State</option>
              <option>Iowa</option>
              <option>Kansas</option>
              <option>Missouri</option>
              <option>Nebraska</option>
              <option>Oklahoma</option>
            </select>
          </p>
          <p>&nbsp;</p>
          <p>
            <label for="phone">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Phone&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <input type="text" name="phone" id="phone" />
           	 <label for="email">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email</label>
           	 <input type="text" name="email" size="30" id="email" />
           	 <br />
            <br />
             <br />
              <br />
            <label for="vin">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;VIN #&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <input type="text" size="45" name="vin" id="vin" />
          </p>
          <p>
           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" id="submit" value="Submit" />
          </p>
        </form>
        
        <script  type="text/javascript">
 var frmvalidator = new Validator("form1");
 frmvalidator.addValidation("f_name","req","Please enter your First Name");
 frmvalidator.addValidation("f_name","maxlen=20",
        "Max length for FirstName is 20");
 frmvalidator.addValidation("l_name","req");
 frmvalidator.addValidation("l_name","maxlen=20");
 frmvalidator.addValidation("add","maxlen=45")
 frmvalidator.addValidation("phone","maxlen=12");
 frmvalidator.addValidation("phone","numeric");
 frmvalidator.addValidation("email","maxlen=50");
 frmvalidator.addValidation("email","req");
 frmvalidator.addValidation("email","email");
 frmvalidator.addValidation("vin","maxlen=17");
 frmvalidator.addValidation("vin","req");
 
 
</script>

        <p>&nbsp;</p>
        
        
        
        </div>
     
    </div>
    
     <div id="rightinfo"><img src="images/images/sidebaright.png" width="309" height="360" /></div>
  </div>
  



</div>

</body>
</html>
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
code, email, form, mail, php

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2