Gary123321 Posted August 15, 2008 Share Posted August 15, 2008 Hi All, I am not a PhP coder but I have hacked around a little in other languages, so if you point me the right way I think I will be alright. Need to email the contents of $_POST. Here is my code: <?php // Your email address $email = "[email protected]"; // The subject $subject = "My Subject"; // The message $message = ($_POST); //$message = "this would work of course, its a string"; mail($email, $subject, $message, "From: $email"); echo "The email has been sent."; ?> This gets the error: Warning: mail() expects parameter 3 to be string because $message needs to be a string. How do I convert $_POST to a string, or loop through it in PhP so it can be emailed as the $message? Thanks Much Link to comment https://forums.phpfreaks.com/topic/119861-solved-how-to-email-_post-in-the-message/ Share on other sites More sharing options...
lemmin Posted August 15, 2008 Share Posted August 15, 2008 $_POST is an array. There will be the name of a variable that you probably want to select or you can do $_POST[0] if you know it is the first one. Or you could loop through them with a foreach($_POST as $var). Link to comment https://forums.phpfreaks.com/topic/119861-solved-how-to-email-_post-in-the-message/#findComment-617482 Share on other sites More sharing options...
kenrbnsn Posted August 15, 2008 Share Posted August 15, 2008 Here's the easiest way. It just dumps the contents of the $_POST array into the message: <?php // Your email address $email = "[email protected]"; // The subject $subject = "My Subject"; // The message $message = print_r($_POST,true); //$message = "this would work of course, its a string"; mail($email, $subject, $message, "From: $email"); echo "The email has been sent."; ?> Ken Link to comment https://forums.phpfreaks.com/topic/119861-solved-how-to-email-_post-in-the-message/#findComment-617483 Share on other sites More sharing options...
Gary123321 Posted August 15, 2008 Author Share Posted August 15, 2008 Awesome Ken!! That works like a champ. It even put each item of the array on separate lines in the email message. (I was kind of worried about that since this will be order data for e-commerce - could be a lot of stuff). Thanks a ton for the super fast answer. Link to comment https://forums.phpfreaks.com/topic/119861-solved-how-to-email-_post-in-the-message/#findComment-617492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.