donglu9872 2016-06-23 17:13
浏览 65

如何在我的php联系表单上修复我的电子邮件标题

On my site when my customers fill out the form I receive the e-mail but the From section instead of showing what the customer input in the form I receive it as "my.hosting.user.name@inmotionhosting.com". I would like to fix this so that I can directly reply to the e-mail the customer input into the form. Here is what my contact.php looks like below.

<?php
// variables start
$name = "";
$email = "";
$message = "";

$name =  trim($_POST['contactNameField']);
$email =  trim($_POST['contactEmailField']);
$message =  trim($_POST['contactMessageTextarea']);
// variables end

// email address starts
$emailAddress = 'info@mydomain.com';
// email address ends

$subject = "mydomain.com | Mobile - Message From: $name";   
$message = "<strong>From:</strong> $name <br/> <strong>E-Mail:</strong> $email </br><br/> <strong>Message:</strong> $message";

$headers = 'From: '. $name . '<' . $email . '>' . "
";
$headers = 'Reply-To: ' . $email . "
";

$headers = 'MIME-Version: 1.0' . "
";
$headers = 'Content-type: text/html; charset=iso-8859-1' . "
";

//send email function starts
mail($emailAddress, $subject, $message, $headers);
//send email function ends
?>
  • 写回答

1条回答 默认 最新

  • dongliao3742 2016-06-23 17:26
    关注

    An assignment to a variable (e.g. $headers = …) changes its value rather than appending to it. You should use the operator .= after initializing the variable first:

    $headers = "";
    $headers .= 'From' . $name . …
    

    etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序