【问题标题】:change sender email address in php form to recipient将php表单中的发件人电子邮件地址更改为收件人
【发布时间】:2012-09-30 20:34:39
【问题描述】:

我正在尝试创建一个简单的 php 电子邮件表单,将提交的内容发送到指定地址,但我要解决的问题是发送电子邮件的地址 - 目前,它从 myusername@ 发送myhostingservice.com,但我希望能够将其更改为简单的 no-reply@mydomain.com 或其他内容。

<?php 

$message = $_POST['message'];

$formcontent="$message";

$recipient = "reciever@example.com";

$subject = "question";

mail($recipient, $subject, $formcontent, $header, '-fno-reply@mydomain.com') or die("Error!");

header("Location: webpage_user_is_redirected_to.html");

?>

【问题讨论】:

  • 不要使用 mail() 使用第三方库,如phpmailer

标签: php forms email


【解决方案1】:

可以使用mail函数的第5个参数:

mail($recipient, $subject, $formcontent, $header, '-fno-replay@mydomain.com');

来自manual

additional_parameters 参数可以用来传递额外的 标记为配置为使用的程序的命令行选项 发送邮件时,由 sendmail_path 配置定义 环境。例如,这可用于设置信封发件人 使用带有 -f sendmail 选项的 sendmail 时的地址。

【讨论】:

  • 我没有看到你的$header?如果您没有任何其他标题信息,请使用 null mail($recipient, $subject, $formcontent, null, '-fno-replay@mydomain.com');
  • 并且不需要将$_POST['message'];传递超过3层变量:mail($recipient, $subject, $_POST['message'], null, '-fno-replay@mydomain.com');
  • 感谢它现在工作得很好!那么它现在会从 $formcontent 开始吗?
  • $formcontent 是表单中发布的消息。你需要把它包装成一个很好的消息:"Dear Luke, the message from the form is " . $_POST['message']; :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多