tstout2 Posted September 18, 2008 Share Posted September 18, 2008 Hey everyone, I am having problems with my mail.php file. Perhaps someone can correct me? My server is shared hosting on GoDaddy.com with Windows, IIS 7 and PHP 5. Thanks for the help! <?PHP $name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $message=$_POST['message']; $ToEmail = "test@kls.com"; $ToSubject = "Message from kls.com"; $EmailBody = "Name: $name\n Email: $email\n Phone: $phone\n Message: $message\n"; $Message = $EmailBody; $headers .= "Content-type: text; charset=iso-8859-1\r\n"; $headers .= "From:".$name." / ".$email."\r\n"; mail($ToEmail,$ToSubject,$Message, $headers); ?> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted September 18, 2008 Share Posted September 18, 2008 where is $headers initialised? the two lines above append data to the end of $headers, not initialise the variable try $headers = "Content-type: text; charset=iso-8859-1\r\n"; $headers .= "From:".$name." / ".$email."\r\n"; Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Sadly, it would seem that does not make it work either. Anyone else have any suggestions? tstout2 Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted September 18, 2008 Share Posted September 18, 2008 tstout2, If you set $success = mail($ToEmail,$ToSubject,$Message, $headers); and the value of $success is false, take a look at this thread... http://www.phpfreaks.com/forums/index.php/topic,214908.0.html By following the instructions and links therein, I got my mail function to work. Good Luck. Scot Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 tstout2, If you set $success = mail($ToEmail,$ToSubject,$Message, $headers); and the value of $success is false, take a look at this thread... http://www.phpfreaks.com/forums/index.php/topic,214908.0.html By following the instructions and links therein, I got my mail function to work. Good Luck. Scot So change mail($ToEmail,$ToSubject,$Message, $headers); to $success = mail($ToEmail,$ToSubject,$Message, $headers); ? I know nothing of PHP. As for your link, it all has to do with linux. As stated above, I am on Windows 2008, IIS 7, PHP5. I don't have a local php5.ini file, but Godaddy told me that there is one set for the system. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Ok... I am really confused now! If mailtest.php and mailform.php WORK, why doesn't mail.php? Mail.php is supposed to be getting the values from a flash form. mailtest.php ----- <?php $to = "email@domain.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "email@domain.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> mailform.php ----- <html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "email@domain.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html> mail.php ----- <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $headers = "From: ".$name." / ".$email."\r\n"; $ToEmail = "kayla@kaylalynnstout.com"; $ToSubject = "Message from KaylaLynnStout.com"; $EmailBody = "Name: $name\n Email: $email\n Phone: $phone\n Message: $message\n"; $Message = $EmailBody; mail($ToEmail,$ToSubject,$Message, $headers); ?> Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted September 18, 2008 Share Posted September 18, 2008 you don't have your mailform.php FORM tag pointing to mail.php its pointing back to iself. Also I would use $_POST or $_GET not $_REQUEST Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 you don't have your mailform.php FORM tag pointing to mail.php its pointing back to iself. Also I would use $_POST or $_GET not $_REQUEST Please re-read the the post right above yours. These are three separate php scripts that I testing. mailtest.php and mailform.php are two separate mail scripts that I used to make sure my system is performing correctly. Those two scripts work. mail.php is the scripts that came with my flash template website. It gets the values from the flash form to be used in mail.php. mail.php does not work. I want to get it working. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2008 Share Posted September 18, 2008 The first step in troubleshooting is to make sure the data input to your code is what you expect? Have you echoed out what is in the $_POST array so that you know that the flash form is even sending anything to your script? You cannot get anything out of a script if there is garbage coming in. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 The first step in troubleshooting is to make sure the data input to your code is what you expect? Have you echoed out what is in the $_POST array so that you know that the flash form is even sending anything to your script? You cannot get anything out of a script if there is garbage coming in. Sounds like a great plan... how do I do this? I am completely new to PHP and don't know how to do what your suggesting. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2008 Share Posted September 18, 2008 Add this at the beginning of your php code - echo "<pre>"; echo "GET:"; print_r($_GET); echo "POST:"; print_r($_POST); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Add this at the beginning of your php code - echo "<pre>"; echo "GET:"; print_r($_GET); echo "POST:"; print_r($_POST); echo "</pre>"; Well, nothing gets echo'ed to the screen. Are you sure this would work with a flash form? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2008 Share Posted September 18, 2008 Either the target file of the flash form is not that file and the code was never requested or where you put the lines in the file was incorrect (you would need to post the current code.) Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Current code.... <?php echo "<pre>"; echo "GET:"; print_r($_GET); echo "POST:"; print_r($_POST); echo "</pre>"; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; $headers = "From: ".$name." / ".$email."\r\n"; $ToEmail = "kayla@[..]"; $ToSubject = "Message from [..].com"; $EmailBody = "Name: $name\n Email: $email\n Phone: $phone\n Message: $message\n"; $Message = $EmailBody; mail($ToEmail,$ToSubject,$Message, $headers); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2008 Share Posted September 18, 2008 If nothing is output, that would mean that your flash file is not requesting that php file. If the get/post arrays are empty, you would at least have the following output from that code - GET:Array ( ) POST:Array ( ) Quote Link to comment Share on other sites More sharing options...
guymclaren Posted September 18, 2008 Share Posted September 18, 2008 I thinks its the windows that is incompatible, I had this problem a few months back with some code that was set up for me. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 I thinks its the windows that is incompatible, I had this problem a few months back with some code that was set up for me. How could that be if those other two scripts work? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 18, 2008 Share Posted September 18, 2008 Godaddy's shared Windows hosting does not officially include php (it is apparently installed but almost no extensions work.) Are the scripts that do work being tried on the same account/domain as the one that does not? You would need to provide information about your flash form to get help with why nothing is working. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Godaddy's shared Windows hosting does not officially include php (it is apparently installed but almost no extensions work.) Are the scripts that do work being tried on the same account/domain as the one that does not? You would need to provide information about your flash form to get help with why nothing is working. Godaddy's new Windows 2008 hosting with IIS 7 does include support for PHP5 only. Both of the scripts above that are working on the same account/domain as the one that does not. This means one of two things... the code is incorrect, or the flash file is not directing to that script. I am working on getting the .swf file open to check it out. I am not at my normal PC, so I am trying to get it installed. tstout2 Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 18, 2008 Author Share Posted September 18, 2008 Alright, I haven't been able to get into the flash file yet, but I did take Godaddy's default PHP form mailer script (see code below) and renamed it to mail.php. I then tried the flash form and it worked (see email output below), so the flash form is calling the correct script and it is the original mail.php code. Now, I don't want to use Godaddy's default script because it it does not create an email from the form and then sends it, it merely sends an email (to an email address that must be specified in the hosting server) with the variables and values outputted. I want my form to create a normal looking email that I could respond to (much like what mailtest.php and mailform.php produce. Godaddy's PHP Code---- <?php $request_method = $_SERVER["REQUEST_METHOD"]; if($request_method == "GET") { $query_vars = $_GET; } elseif ($request_method == "POST") { $query_vars = $_POST; } reset($query_vars); $t = date("U"); $file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t; $fp = fopen($file,"w"); while (list ($key, $val) = each ($query_vars)) { fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); fputs($fp,"$val\r\n"); fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n"); if ($key == "redirect") { $landing_page = $val; } } fclose($fp); if ($landing_page != "") { header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page"); } else { header("Location: http://".$_SERVER["HTTP_HOST"]."/"); } ?> Godaddy's Output Email---- from test@gmail.com to test@kls.com date Thu, Sep 18, 2008 at 1:40 PM subject Form submission from kls.com mailed-by bounce.secureserver.net email: [...] message: test email from flash name: Terry Stout phone: 555.555.5555 ----------------------------------------------------------------- This e-mail was generated from a form submission on your website: Quote Link to comment Share on other sites More sharing options...
Brian W Posted September 18, 2008 Share Posted September 18, 2008 I hop I don't sound too stupid, but look at the basic real quick. I think you cant have your script like this... $EmailBody = "Name: $name\n Email: $email\n Phone: $phone\n Message: $message\n"; its got to be like $EmailBody = "Name: ".$name."\n Email: ".$email"\n Phone: ".$phone."\n Message: ".$message."\n"; Just like using echo/print..."".$."".$."" If I'm wrong, thats great, it'll save me time in the future. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 19, 2008 Author Share Posted September 19, 2008 I hop I don't sound too stupid, but look at the basic real quick. I think you cant have your script like this... $EmailBody = "Name: $name\n Email: $email\n Phone: $phone\n Message: $message\n"; its got to be like $EmailBody = "Name: ".$name."\n Email: ".$email"\n Phone: ".$phone."\n Message: ".$message."\n"; Just like using echo/print..."".$."".$."" If I'm wrong, thats great, it'll save me time in the future. Didn't make a difference for me. If you look back at the code for the two scripts that work, they don't use the syntax your suggesting. Quote Link to comment Share on other sites More sharing options...
tstout2 Posted September 19, 2008 Author Share Posted September 19, 2008 FINALLY!!!! I had to do hours of research and piece together lots of code, but I finally have something that works the way I want it to. Thanks to everyone for the help. tstout2 Final Working Code---- <?php /* Subject and Email Variables */ $subject = 'Message from KLS.com'; $to = 'email@kls.com'; /* Gathering Data Variables */ $email = $_POST['email']; $name = $_POST['name']; $phone = $_POST['phone']; $message = $_POST['message']; /* Build Email Body */ $body = <<<EOD Name: $name Email: $email Phone Number: $phone Message: $message EOD; /* Build Email Headers */ $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n"; $headers .= "From: $name <$email>\r\n"; $headers .= "Reply-To: " .$email. "\r\n"; /* Send Email */ $success = mail($to, $subject, $body, $headers); ?> 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.