php - PHP 联系表 : Allowing the user to send me an email

标签 php email

在我的网站上,我有一个联系表单,用户可以在其中报告错误或提交功能请求。该表单包含主题消息

我希望表单直接通过 PHPMailer 或 PHP 的内置邮件功能向我发送电子邮件。

这里的问题是生成电子邮件时,发件人必须是我拥有的地址,而不是实际用户的电子邮件地址。原因很明显,因为我们不应该被允许冒充其他人。不过,我希望能够直接从我的收件箱给我的用户发电子邮件,但我无法做到这一点,因为我无法在脚本中使用他们的地址给自己发电子邮件。

那么构建联系表单的最佳方式是什么? 我能想到的唯一解决方法是将消息+发件人地址插入数据库,然后从那里手动读取......这是一个巨大的麻烦。

如果有任何建议,我将不胜感激。

最佳答案

设置Reply-To电子邮件 header ,这样您就会收到如下内容:

<?php
$headers = 'From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="750c1a0035100d14180519105b161a18" rel="noreferrer noopener nofollow">[email protected]</a>' . "\r\n";
// Set the sender address as Reply-to below
$headers .= 'Reply-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d5e484349485f6d48554c405d4148034e4240" rel="noreferrer noopener nofollow">[email protected]</a>' . "\r\n";

mail('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed948298ad88958c809d8188c38e8280" rel="noreferrer noopener nofollow">[email protected]</a>', 'Subject here', 'The message goes here', $headers);
?>

这样您将成为发件人,但是当您点击邮件客户端中的回复按钮时,它将默认回复到 Reply-To header 中列出的地址。

关于php - PHP 联系表 : Allowing the user to send me an email,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13668882/

相关文章:

PHP 脚本提前结束,没有错误证据并且超时设置为 0

iOS:如何在已经显示邮件撰写 View 时在后台创建/准备自定义电子邮件附件?

java - 如何使用指定客户端以编程方式从 Java 发送电子邮件附件

sharepoint - 如何在更新代码中的项目时暂时禁用电子邮件通知?

Python smtplib 破坏 html 电子邮件

javascript - Electron SQL 安全

php - 管理多个 Cookie "Domains"

ruby-on-rails - 连接被拒绝 - connect(2) Ruby on Rails 邮件设置

php - pdo 准备转义单引号

php - Dotrine 2 和 Zf2 整合