简体   繁体   English

联系表格回复发件人

[英]Contact form reply to sender

So I've completed a contact form made in PHP. After testing it sends emails, but in the email header it is not capturing the sender's name or email address.所以我已经完成了在 PHP 中制作的联系表格。经过测试它发送电子邮件,但在 email header 中它没有捕获发件人的姓名或 email 地址。 It shows up as sh-908129268@eu.hosting-webspace.io它显示为 sh-908129268@eu.hosting-webspace.io

Is there a way to correct that?有办法纠正吗? I need to be able to respond to emails.我需要能够回复电子邮件。

The inputs are as follows:输入如下:

<form id="contact" action="<?= $_SERVER['PHP_SELF']; ?>" method="post">

<input class="input is-small" type="text" name="name" placeholder="Text input" value="<?= $name ?>" >
<p class="help is-danger"><?= $name_error ?></p>

<input class="input" type="email" name="email" placeholder="Email Address" value="<?= $email?>">
<p class="help is-danger"><?= $email_error?></p>

// back-end file

$sendTo = 'test@email.com';
        $subject = 'Business Enquiry';
        $headers = "";

        $headers .= "Sent From: ".$name. "\r\n";
        $headers .= "Reply To: ".$email. "\r\n";
        $headers .= "Message: ".$message. "\r\n";

        if (mail($sendTo, $subject, $message, $headers)) {

            $success = "Thank you for your message, I will reply as soon as I can.";
            $name = $email = $message = ''; // resets all fields
        } 

You cannot pick the names of the headers freely, you have to adhere to the standard ( RFC 5322 Inte.net Message Format ).您不能随意选择标头的名称,您必须遵守标准( RFC 5322 Inte.net Message Format )。

Your header " Sent From " should be just From , your header " Reply To " should be Reply-To and your header "Message" shouldn't be in the headers at all - you already pass the message as such into the mail function.您的 header“发送自”应该只是From ,您的 header“回复”应该是Reply-To ,您的 header“消息”根本不应该出现在标题中 - 您已经将消息原样传递到邮件 function 中。

All fixed now, thanks.现在都修好了,谢谢。 All I needed was to specify one header,我只需要指定一个 header,

$headers = "From: ".$email; $headers = "发件人:".$email;

So it's just $subject and $headers所以它只是 $subject 和 $headers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM