在 html 到 php 之间传递变量值(服务器端代码)邮件功能

pass variable value between html to php (server side code) mail function

我正在尝试在我的网站上创建一个联系我们的表单(我想在不打开邮件客户端的情况下发送电子邮件 window),为此我知道我必须使用 Server side code 用于处理 mail() 函数这是我目前所发现的:

我在 html 页的表格:

<form action="sendmail.php">
                        <input type="text" placeholder="Name" required="">
                        <input type="text" placeholder="Email" required="">
                        <input type="text" placeholder="Subject" required="">
                        <textarea placeholder="Message" required=""></textarea>
                        <input type="submit" value="SEND">
                    </form>

我的 sendmail.php 文件(在服务器端)

  <?php
$to      = 'support.@mydomain.com';
$subject = 'the subject'; // here how can i get the subject 
$message = 'hello'; // here how can i get the message 
$headers = 'From: webmaster@example.com' . "\r\n" . // here 

如何获取动态值?

    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
?> 

那么如何将用户在 html 表单中输入的值作为参数传递到我的 php 函数中??

更新、尝试:

$subject = 'echo htmlspecialchars($_P‌​OST['subject']);';
$message = 'echo htmlspecialchars($_P‌​OST['message']);';
$headers = 'From: echo htmlspecialchars($_P‌​OST['email']);' . "\r\n" . 'Reply-To: webmaster@example.co‌​m' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?>

错误:

Parse error: syntax error, unexpected T_STRING in /home/a9700859/publi‌​c_html/sendmail.php on line 3

您可以使用 $_POST 方法实现此目的。

HTML 页面。

<form method="POST" action="sendmail.php">
 <input type="text" name="sender_name" placeholder="Name" required="">
 <input type="text" name="sender_email" placeholder="Email" required="">
 <input type="text" name="subject" placeholder="Subject" required="">
 <textarea placeholder="Message" name="message" required=""></textarea>
  <input type="submit" name="send" value="SEND">
</form>

这是你的sendmail.php

<?php
if($_POST['send'] == 'SEND'){

$to      = 'support.@mydomain.com'; // email where message is sent
$subject = $_POST['subject']; // here how can i get the subject 
$message = $_POST['message']; // here how can i get the message 
$headers = 'From: webmaster@example.com' . "\r\n" . // here how can i get the the dynamic values   
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
}
?>