Jump to content

[SOLVED] How to email $_POST in the Message?


Gary123321

Recommended Posts

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 :)

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

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.  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.