Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在html到php(服务器端代码)邮件函数之间传递变量值_Php_Email_Server Side - Fatal编程技术网

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

在html到php(服务器端代码)邮件函数之间传递变量值,php,email,server-side,Php,Email,Server Side,我正在尝试在我的网站中创建一个联系我们表单(我希望在不打开邮件客户端窗口的情况下发送电子邮件),为此,我知道我必须使用服务器端代码来处理mail()函数。到目前为止,我发现: html页面中的我的表单: <form action="sendmail.php"> <input type="text" placeholder="Name" required=""> <inpu

我正在尝试在我的网站中创建一个联系我们表单(我希望在不打开邮件客户端窗口的情况下发送电子邮件),为此,我知道我必须使用
服务器端代码来处理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>
那么,如何将用户在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); ?>
错误:

分析错误:语法错误,在/home/a9700859/publi中出现意外的T_字符串‌​第3行的c_html/sendmail.php


您可以使用$\u 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);
}
?>

您可以使用$\u 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);
}
?>


您希望php代码在html文件中工作吗?不,我想将用户输入的数据转发到php函数
$\u GET
&
$\u POST
?您尝试了什么?你犯了什么错误?如果没有显示错误,请发布PHP错误日志。谢谢。你想让php代码在html文件中工作吗?不,我想把用户输入的数据转发到php函数
$\u GET
&
$\u POST
?你尝试了什么?你犯了什么错误?如果没有显示错误,请发布PHP错误日志。谢谢你看,谢谢,伙计,现在工作很好,谢谢你的努力,伙计,kikuyu1,我这里有问题,你能帮忙吗<代码>$headers=From:$\u POST['sender\u email']。“\r\n”。”回复:$_POST['sender_email'];'。“\r\n”。”X-Mailer:PHP/”。phpversion()我收到一个错误,在代码第9行的代码中显示
解析错误:语法错误,意外“:”‌​']."  . "\r\n.“回复:”.$\u POST[“发件人”\u电子邮件‌​']." ; . "\r\n“'X-Mailer:PHP/”.phpversion();
了解如何在html中连接PHP。嘿,男人仍然会在代码第9行的代码中遇到此错误
解析错误:语法错误,意外的'''headers.=''From:“.$\u POST['sender\u name.”​']." \r\n“;$headers.=”回复:“.$\u POST['sender\u email”‌​'].“\r\n”;$headers.='Content type:text/html;charset=iso-8859-1.”“\r\n”;
尝试使用此替代品谢谢你现在工作正常,感谢你的努力。我在这里遇到了问题。你能帮忙吗?
$headers=来自:$\u POST['sender\u email']。”\r\n“…回复:$\u POST['sender\u email']。”\r\n”“'X-Mailer:PHP/'.phpversion();
我收到一个错误,在代码第9行的代码中,
解析错误:语法错误,意外”:“发件人:'”‌​']."  . "\r\n.“回复:”.$\u POST[“发件人”\u电子邮件‌​']." ; . "\r\n“'X-Mailer:PHP/”.phpversion();
了解如何在html中连接PHP。嘿,男人仍然会在代码第9行的代码中遇到此错误
解析错误:语法错误,意外的'''headers.=''From:“.$\u POST['sender\u name.”​']." \r\n“;$headers.=”回复:“.$\u POST['sender\u email”‌​'].“\r\n”;$headers.='Content type:text/html;charset=iso-8859-1”“\r\n”
尝试改用此选项。”