$name、$email 和 $message 变量在电子邮件中显示为文本

$name, $email, and $message variables show as text in email

我对 PHP 知之甚少,正试图为我正在帮助开发的网站制作联系表。 PHP 表单发送了电子邮件,但出于某种原因没有将变量替换为联系页面中的输入字段。该网站是 SWFDA。这是我创建的 PHP 表格:

<?php

if(!isset($_POST['submit'])) {

$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

$email_from = 'myemail@website.com';

$email_to = 'myemail@website.com';

$email_subject = 'Contact Form Submission (Under testing)';
$email_body = 'You have received a form submission from $name .
Email: $visitor_email .
Here is the message: $message'.;

mail($email_to,$email_subject,$email_body);

header('Location: contact-sent.html');

}

?>

这是表单的 HTML。

<form method="post" action="contactForm.php">
    <div class="row uniform">
        <div class="6u 12u$(large) 6u(medium) 12u$(xsmall)">
            <label for="name">Name</label>
            <input type="text" name="name" id="name" required/>
        </div>
        <div class="6u$ 12u$(large) 6u$(medium) 12u$(xsmall)">
            <label for="email">Email</label>
            <input type="email" name="email" id="email" required/>
        </div>
        <div class="12u$">
            <label for="message">Message</label>
            <textarea name="message" id="message" rows="5" required></textarea>
        </div>
        <div class="12u$">
            <ul class="actions">
                <li><input type="submit" value="Send Message" class="special" /></li>
                <li><input type="reset" value="Reset" /></li>
            </ul>
        </div>
    </div>
</form>

收到的电子邮件如下所示:

您已收到 $name 提交的表单。
电子邮件:$visitor_email。
这是消息:$message.

这样试试,

$email_body = 'You have received a form submission from '.$name.'
Email: '.$visitor_email.'
Here is the message: '.$message;

或使用双引号 " "

$email_body = "You have received a form submission from $name
Email: $visitor_email
Here is the message: $message";

只需将 $email_body 中的单引号 (') 更改为双引号 ("),那么您的电子邮件应如下所示:

<?php

if(!isset($_POST['submit'])) {

$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

$email_from = 'myemail@website.com';

$email_to = 'myemail@website.com';

$email_subject = 'Contact Form Submission (Under testing)';
$email_body = "You have received a form submission from $name .
Email: $visitor_email .
Here is the message: $message".;

mail($email_to,$email_subject,$email_body);

header("Location: contact-sent.html");

}

?>