【问题标题】:Allowing someone to reply to an email sent from a site with a php contact form允许某人使用 php 联系表单回复从站点发送的电子邮件
【发布时间】:2018-02-07 14:14:55
【问题描述】:

我创建了一个 php 联系表格,以允许某人通过其网站上的表格联系公司。

代码工作正常,电子邮件发送没有问题。唯一的问题是,当发送电子邮件并且公司希望重播它时,它会发送到一个陌生的电子邮件,而不是用户在联系表单中输入的电子邮件。有没有办法解决这个问题?

这是联系表单的 php 代码。

<?php
  if (isset($_POST["submit"])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    

    $from = 'site user'; 
    $to = 'example@example.com'; 
    $subject = 'Message from a site user';
    
    $body ="From: $name\n E-Mail: $email\n Message:\n $message";
 
    if (!$_POST['name']) {
      $errorName = 'Please enter your name';
    }
    
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
      $errorEmail = 'Please enter a valid email address';
    }
    
    
    if (!$_POST['message']) {
      $errorMessage = 'Please enter your message';
    }
    
if (!$errorName && !$errorEmail && !$errorMessage) {
  if (mail ($to, $subject, $body, $from)) {
    $result='<div class="alert alert-success">Thank You! I will be in touch</div>';
  } else {
    $result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
  }
}
  }
?>

【问题讨论】:

标签: php forms email


【解决方案1】:

在标题中添加Reply To

不要按原样传递 $from,而是执行以下操作:

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

【讨论】:

  • 遗憾的是这也没有解决问题
  • 当你点击回复时,你的邮件试图回复谁?
  • 它转到 example@p3plcpml0853.prod.phx3.secureserver.net
  • 实际上它现在正在工作,我觉得我的电子邮件很有趣,谢谢你的帮助。
猜你喜欢
  • 2012-11-20
  • 1970-01-01
  • 2016-10-20
  • 2019-09-04
  • 1970-01-01
  • 2017-07-16
  • 2012-02-25
  • 2019-01-30
  • 2021-10-25
相关资源
最近更新 更多