我想在表单提交的消息中包含用户名

时间:2012-05-31 18:10:57

标签: php html

这是我的PHP代码,我想以某种方式更改用户在提交表单时看到的消息,其中包含“Ben,您的消息已被发送!”之类的名称。我也希望保持它的样式,但现在包括名称。

<?php
        if(isset($_POST['submit'])){

            $to = "benlevygraphics@gmail.com";
            $headers = "From: " . $_POST['email'];
            $subject = "Ben, you have been contacted...";
            $body = "Name: " . $_POST['name'] . "\nEmail: " . $_POST['email'] . "\nWebsite: " . $_POST['web'] . "\nMessage: " . $_POST['message'];

            if(mail($to, $subject, $body, $headers)){

                echo("<p class=contactformsent>Your message has been sent!</p>");
            }
            else{
               echo("<p class=contactformnotsent>Message delivery failed...</p>");
            }
       }

?>

2 个答案:

答案 0 :(得分:1)

试试这个

$name = $_POST['name'];
echo("<p class=contactformsent>".$name." Your message has been sent!</p>");

答案 1 :(得分:0)

所以在邮件中插入名称:

echo("<p class=contactformsent>".$_POST['name'].", your message has been sent!</p>");