开发者

PHP mail() Message Contents

Im trying to sent a message which contains the post values of a form. I dont think im putting them together right as its only sending the first POST value (make).

$message = $_POS开发者_如何学运维T['make'];
$_POST['model'];
$_POST['Street'];
$_POST['towncity'];

is this the correct way to put them together so that all 4 of them send?

Regards

Ross


There are many ways you can format this message. I encourage you to read this page of the PHP Documentation.

You can for example, concatenate all the values together (one on each line).

$message = $_POST['make'] . "\n"
. $_POST['model'] . "\n"
. $_POST['Street'] . "\n"
. $_POST['towncity'];


No, I don't think that would work!

Try:

$message=  $_POST['make'] . $_POST['model'] . $_POST['Street'] . $_POST['towncity'];

But this would cause it to write everything in one line. I would suggest this:

$message="Make: " . $_POST['make'] . "\n Model: " . $_POST['model']; // etc...

Or if it's a HTML coded email, change \n to


$message = $_POST['make'] . $_POST['model'] . $_POST['Street'] . $_POST['towncity'];

BUT!

don't send values in the same form as they are posted. It's dangerous, and you might get exploited. Either make sure the content is properly cleaned, or even better, use library like Swift Mailer or PHPMailer.


Try this:

$message = $_POST['make'] . $_POST['model'] . $_POST['Street'] . $_POST['towncity'];

But be careful! Check for some dangerous php and mysql codes in the first place to make your code unhurt.


Use the concatenate operator. A semi-colon signifies the end of that current block of code. The concatenate strings the variables together:

 $message = $_POST['make']
.$_POST['model']
.$_POST['Street']
.$_POST['towncity'];

Using $_POST values is very insecure however. Take a look at this example for a basic tutorial on how to protect against attacks and injections.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜