mantona Posted December 31, 2007 Share Posted December 31, 2007 I kindly received help from someone on this website a few days ago concerning the creation of a form. The form seems to work great but unfortunately sometimes I get a form through to me via email which says the following: Array () It usually says when someone contacts me: Array ( [TITLE] => [FORENAME] => [sURNAME] => => [TELEPHONE1] => [TELEPHONE2] => [ENQUIRY] => [submit] => submit ) Is this normal? Is this a form going wrong somehow? Am I missing contact submissions?. Please help Please note the code below: ********************************* $headers = "From: webmaster@MYWEBSITE.co.uk\r\n" . "X-Mailer: PHP" . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // this emails you the results of the form mail( "Webmaster@MYWEBSITE.co.uk", "New Contact Message", print_r( $_POST, true),"$headers"); // this will redriect the user somewhere away from this page header("Location: http://www.MYWEBSITE.co.uk/thanks.html"); ?> ****************** Thank you Ryan Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/ Share on other sites More sharing options...
raku Posted December 31, 2007 Share Posted December 31, 2007 Take a look at http://us.php.net/print_r I'm not sure that you want to directly output the information in the array like that in your email. You may want to consider making a string with the message in it by processing the information in the array. Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426322 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2007 Share Posted December 31, 2007 That code is rather basic. If that is all of the code, it is not checking that a form was even submitted and as a result it will send an email with an empty $_POST array any time someone or something (search engine, spam bot) simply visits the page that code is on. At a minimum it needs to check that the $_POST variable that corresponds to the name of your submit button is set. Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426325 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 Please post the all of the script that sends the email, as well as the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426326 Share on other sites More sharing options...
mantona Posted December 31, 2007 Author Share Posted December 31, 2007 Sorry, I'm very new to all this stuff. It's all in the file called process.php Do I need to post anything else? I apologize for being stupid on this one but I am very new at the php side of things Thank you Ryan Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426335 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 You need to post the source of your process.php here between the tags. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426341 Share on other sites More sharing options...
mantona Posted December 31, 2007 Author Share Posted December 31, 2007 The code that is above is what the process.php contains. I do not have tags? Should they be in the process.php file? Thank you Ryan Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426343 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 No, The tags are used when you post source in this forum. Go into your editor, copy all the code, and paste the copied code into a reply. Put the tag before your code and after it. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426346 Share on other sites More sharing options...
mantona Posted December 31, 2007 Author Share Posted December 31, 2007 Thanks. Code as follows: <?php $headers = "From: webmaster@MYWEBSITE.co.uk\r\n" . "X-Mailer: PHP" . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // this emails you the results of the form mail( "Webmaster@MYWEBSITE.co.uk", "New Contact Message", print_r( $_POST, true),"$headers"); // this will redriect the user somewhere away from this page header("location: http://www.MYWEBSITE.co.uk/thanks.html"); ?> Thank you Ryan Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426348 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 If there is any chance that this script can be invoked directly instead of being invoked from the form being submitted, then the $_POST array would be empty and that would cause your problem. I would test to make sure the process was invoked via the form. Try: <?php if (isset($_POST['submit'])) { $headers = "From: webmaster@MYWEBSITE.co.uk\r\n" . "X-Mailer: PHP" . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; // this emails you the results of the form mail( "Webmaster@MYWEBSITE.co.uk", "New Contact Message", print_r( $_POST, true),$headers); // this will redriect the user somewhere away from this page header("location: http://www.MYWEBSITE.co.uk/thanks.html"); } else { echo "Script invoked incorrectly." ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426860 Share on other sites More sharing options...
mr_mind Posted December 31, 2007 Share Posted December 31, 2007 Alright well your form was not mailing to anyone and you did not check to see if the form was mailed properly I have structured the message section of the email to do what you want it to though i dont think that is a good idea It would also help alot if you could show us the form <?php if(isset($_POST['submit'])) { $from = $_POST['EMAIL']; $subject = "New Contact Message"; $message = ""; foreach($_POST as $description => $post_option) { $message .= $description . ': ' . $post_option . "\r\n"; } $to = "Webmaster@MYWEBSITE.co.uk"; $headers = "From: webmaster@MYWEBSITE.co.uk" . "\r\n"; $headers .= "X-Mailer: PHP" . phpversion() . "\r\n"; $headers .= "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-Type: text/html; charset=utf-8" . "\r\n"; $headers .= "Content-Transfer-Encoding: 8bit" . "\r\n"; if(mail($to,$subject,$message,$from,$headers)) { header("location: http://www.MYWEBSITE.co.uk/thanks.html"); } else { print 'Failed sending message.'; if(error_get_last() != '') { print '<br />An error was retrieved from the system:<br />'; print error_get_last(); } else { print '<br />The system did not return an error'; } } } else { // Put the form here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426867 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 The original mail() call did have a "to" field, it was just entered as a literal. You don't need a variable. Same goes for the body of the message. Using print_r() with the second parameter of "true" will put the results into the message, There's no need for the foreach loop you have. Also, your foreach loop only puts in the value of the submitted fields, not the names of the fields, which is rather meaningless. To see the source of the form, go the URL the OP mentioned a few posts ago and click on "Show source" in your browser. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426872 Share on other sites More sharing options...
mr_mind Posted December 31, 2007 Share Posted December 31, 2007 The original mail() call did have a "to" field, it was just entered as a literal. You don't need a variable. Same goes for the body of the message. Using print_r() with the second parameter of "true" will put the results into the message, There's no need for the foreach loop you have. Also, your foreach loop only puts in the value of the submitted fields, not the names of the fields, which is rather meaningless. To see the source of the form, go the URL the OP mentioned a few posts ago and click on "Show source" in your browser. Ken 1). I am sorry when i said to i was looking at something else, i meant from, 2). You dont need a variable it is just easier to read 3). using print_r is not the best way to do it as print_r can not be formatted 4). my foreach loop shows the description of the posted field as well 5). I do not see a link unless MYWEBSITE.co.uk is a link which i doubt Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426877 Share on other sites More sharing options...
kenrbnsn Posted December 31, 2007 Share Posted December 31, 2007 1). I am sorry when i said to i was looking at something else, i meant from, 2). You dont need a variable it is just easier to read 3). using print_r is not the best way to do it as print_r can not be formatted 4). my foreach loop shows the description of the posted field as well 5). I do not see a link unless MYWEBSITE.co.uk is a link which i doubt 1) The OP did include a "from" line 2) Depends on who's reading it. 3) The OP wants to email the contents of the form to himself. IMHO, print_r is the easiest way to do that. I use it all the time. The output looks fine in a text based email message. 4) I believe you were editing your response when I posted my response 5) Sorry, I was thinking of a different question. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426884 Share on other sites More sharing options...
mr_mind Posted December 31, 2007 Share Posted December 31, 2007 1) The OP did include a "from" line 2) Depends on who's reading it. 3) The OP wants to email the contents of the form to himself. IMHO, print_r is the easiest way to do that. I use it all the time. The output looks fine in a text based email message. 4) I believe you were editing your response when I posted my response 5) Sorry, I was thinking of a different question. Ken 1). i do not see a from in this string "mail( "Webmaster@MYWEBSITE.co.uk", "New Contact Message", print_r( $_POST, true),$headers);" 2). Well im sorry but i find it easier when i know exactly what each field is 3). It may be the easiest but it is not the best, so i guess your point is to be lazy Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-426905 Share on other sites More sharing options...
mantona Posted January 1, 2008 Author Share Posted January 1, 2008 Thanks for all your help. I really appreciate it. Unfortunately though I'm completely lost to what your suggestions are. Can you help? Ryan Quote Link to comment https://forums.phpfreaks.com/topic/83788-is-my-form-correct-why-do-i-sometimes-get-this-response/#findComment-427436 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.