samporras Posted January 24, 2007 Share Posted January 24, 2007 hi guys. I'm working on my frist PHP script and running into a few stumbling blocks (code below). The email is being sent successfully, but none of the variable data is populated. Here is the page http://www.sitesamurai.com/signupForm.php. Any help would be appreciated. Thanks! Sam >$name = $_REQUEST["userName"]; $teamName = $_REQUEST["teamName"]; $phone = $_REQUEST["phone1"] . "-" . $_REQUEST["phone2"] . "-" . $_REQUEST["phone3"]; $city = $_REQUEST["city"]; $state = $_REQUEST["state"]; $zipCode = $_REQUEST["zipCode"]; $country = $_REQUEST["country"]; $comments = $_REQUEST["comments"]; function PopulateMessage($name,$teamName,$phone,$city,$state,$zipCode,$country,$comments) { $sMessage = '<html><head><title>User Inquiry</title></head><body><p>'; $sMessage .= '<strong>name:</strong><br>' . $name + '<br><br>'; $sMessage .= '<strong>team name:</strong><br>' . $teamName . '<br><br>'; $sMessage .= '<strong>phone:</strong><br>' . $phone . '<br><br>'; $sMessage .= '<strong>city:</strong><br>' . $city . '<br><br>'; $sMessage .= '<strong>state:</strong><br>' . $state . '<br><br>'; $sMessage .= '<strong>zip code:</strong><br>' . $zipCode . '<br><br>'; $sMessage .= '<strong>country:</strong><br>' . $country . '<br><br>'; $sMessage .= '<strong>comments:</strong><br>' . $comments . '<br><br>'; $sMessage .= '</p></body></html>'; return $sMessage; } //populate email message $Message = PopulateMessage($name,$teamName,$phone,$city,$state,$zipCode,$country,$comments); //populate email headers $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: <xxx@xxxxx.com>' . "\r\n"; //send mail mail("xxx@xxxxx.com","Test Email",$Message,$headers); Quote Link to comment Share on other sites More sharing options...
samporras Posted January 25, 2007 Author Share Posted January 25, 2007 (edited) The email is being sent successfully, but none of the variable data is populated. Here is the page I figured out what was going on. I was using a type="button" input instead of a type="submit". The page was not posting which would explain why the variables i created were never populated. This leads me to another question. Does anyone know of a function that exists in php to redirect from one page to another? I was not able to find this in any of the books i own. I would like to call this function and redirect to another page after the mail() function has been executed. Thanks. Sam Edited January 25, 2007 by samporras Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted January 25, 2007 Share Posted January 25, 2007 >header("Location: http://www.example.com/"); /* Redirect browser */ but you can't output anything first, not even a space in the code Quote Link to comment Share on other sites More sharing options...
samporras Posted January 25, 2007 Author Share Posted January 25, 2007 >header("Location: http://www.example.com/"); /* Redirect browser */ but you can't output anything first, not even a space in the code Thanks Don I'm not 100% sure i follow what you're saying. What would i want to output when redirecting from one page to the other? Quote Link to comment Share on other sites More sharing options...
click Posted January 25, 2007 Share Posted January 25, 2007 It's usually unintentional output that messes you up. For instance, a blank line above the opening "<?php" tag or in an included file. When Apache parses the page it will go ahead and send the headers and blank line before getting to the php header code. In this case, php will complain that the headers have already been sent. Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted January 26, 2007 Share Posted January 26, 2007 Or if in the code before the header location you have a line for spacing besure there are no spaces in the line always comment the blank lines before. Quote Link to comment Share on other sites More sharing options...
click Posted January 26, 2007 Share Posted January 26, 2007 oh jeez, now I'm confused. Just to clarify, once you're inside the <?php ?> tags you can use all the blank lines and spaces you want. You're only concerned about stuff that would be output to the browser. Quote Link to comment Share on other sites More sharing options...
TCH-Don Posted January 26, 2007 Share Posted January 26, 2007 Whoops, you are right. Quote Link to comment Share on other sites More sharing options...
surefire Posted January 26, 2007 Share Posted January 26, 2007 Two quick things. You can address some of these header issues by putting this at the very beginning of the php code (still can't have space or line break or any output before <?php) ><?php ob_start(); The other thing is that you should consider replacing $_REQUEST with $_POST (or $_GET). It's more specific, and therefore more secure. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted January 26, 2007 Share Posted January 26, 2007 I would also change this line: >mail("xxx@xxxxx.com","Test Email",$Message,$headers); to read like this: >mail("xxx@xxxxx.com","Test Email",$Message,$headers "-f".$myemail); Set up $myemail to a valid from email address. Quote Link to comment Share on other sites More sharing options...
carbonize Posted January 29, 2007 Share Posted January 29, 2007 Just some minor suggestions with your code 1 - Always use single quotes around strings and not doubles. This is because PHP reads through double quoted strings looking for variables everytime it comes cross it. Same applies to array keys. You only need double quotes when using special characters such as \n \t etc. 2 - use "NAME" <email@address.com> to add a more personal touch to your emails (I know you are only sending to yourself right now). Quote Link to comment Share on other sites More sharing options...
samporras Posted January 30, 2007 Author Share Posted January 30, 2007 I would also change this line: >mail("xxx@xxxxx.com","Test Email",$Message,$headers); to read like this: >mail("xxx@xxxxx.com","Test Email",$Message,$headers "-f".$myemail); Set up $myemail to a valid from email address. Thanks Bruce. i thought i took care of that when i set up my $headers variable (line 4 of the below code). Is there a preferred way to declare a "from" email address? >//populate email headers $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: <xxx@xxxxx.com>' . "\r\n"; Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted January 30, 2007 Share Posted January 30, 2007 >"-f".$myemail What you have sets the from in the email message. The above authenticates you as sending the message through the server. Quote Link to comment 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.