【问题标题】:Reply-to header in contact form PHP联系表单PHP中的回复标题
【发布时间】:2016-05-07 08:37:55
【问题描述】:
// Subject of your email
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.'; 
// Recipient's E-mail
$to = 'recipient@domain.com';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Sender's E-mail
$headers .= "From: Contact Form (Domain.com) <no-reply@domain.com>"; 
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";

if (@mail($to, $subject, $message, $headers)) {
    // Transfer the value 'sent' to ajax function for showing success message.
  echo 'sent';
} else {
  // Transfer the value 'failed' to ajax function for showing error message.
  echo 'failed';
}

如何在此处放置回复标题? 回复邮件应该是填写表格时输入的邮件,不知道PHP有没有人能帮帮我?谢谢

【问题讨论】:

  • $headers 的其余部分完全一样...如果您正在使用 mime 等“复杂”消息,您应该使用适当的邮件包,如 phpmailer 或 swiftmailer . php 内置的mail() 基本上就是个玩具。

标签: php forms contact


【解决方案1】:
<?php
$subject = $_REQUEST['subject'] . ' - Personal website contact form submittion.'; // Subject of your email
$to = 'recipient@domain.com'; //Recipient's E-mail

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Contact Form (Domain.com) <no-reply@domain.com>\r\n"; // Sender's E-mail
$headers .= "Reply-To: ".$_REQUEST['email']."<". $_REQUEST['email'].">\r\n" .
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= 'Email: ' . $_REQUEST['email'] . "<br>";
$message .= 'Message: ' . $_REQUEST['message'] . "<br>";

if (@mail($to, $subject, $message, $headers))
{
    // Transfer the value 'sent' to ajax function for showing success message.
    echo 'sent';
}
else
{
    // Transfer the value 'failed' to ajax function for showing error message.
    echo 'failed';
}
?>

【讨论】:

  • 你能帮我把它添加到我上面提到的代码中吗?
  • 不行,添加代码后,消息发送不出去。
  • 我尝试了更新的代码。它显示消息无法发送。
  • 你能转储堆栈跟踪吗?
  • 你能帮我写一个简单的PHP代码吗?这个用 mime 之类的东西太复杂了。?
猜你喜欢
  • 2013-03-14
  • 2018-09-01
  • 2023-03-06
  • 2017-08-26
  • 2016-03-26
  • 2013-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多