【问题标题】:Email form data to user's email通过电子邮件将表单数据发送到用户的电子邮件
【发布时间】:2013-10-05 11:16:56
【问题描述】:

我正在尝试在提交者单击“提交”按钮后将提交者在文本区域中填写的内容通过电子邮件发送给他。 “current_user”是一个wordpress codex,它获取登录用户的电子邮件。

我的代码确实打印出正确的电子邮件 + 我在文本区域中填写的内容, 但它不会将其发送到此电子邮件。 我不知道要解决什么。 感谢您的帮助!

<form action="#" method="post">
<textarea  name="lesson1"></textarea><br>
 <input type="submit" name="Send" value="Send to your Email" />
</form>
 </div>

 <?php
global $current_user;
get_currentuserinfo();
 $email = $current_user->user_email;
 $lesson1 = htmlspecialchars($_POST['lesson1']);
echo $lesson1, $email;
$email_subject = "Test E-Mail (This is the subject of the E-Mail)";
(mail($email, $email_subject, $lesson1);
if(mail($email, $email_subject, $lesson1)){
echo "The email($email_subject) was successfully sent.";
} else {
echo "The email($email_subject) was NOT sent.";
?>

【问题讨论】:

  • 为什么要使用 txtarea?您可以使用电子邮件输入字段
  • 你可以不使用电子邮件输入。然后用PHP抓取邮件
  • 嘿,谢谢。我的 textarea 没有收到电子邮件地址,我是从 wordpress 数据库中获取的。我的 textarea 应该是我的电子邮件的正文。我该怎么做?

标签: php html wordpress forms email


【解决方案1】:

您已经打开了 else 块,但从未在下面的部分中关闭它:

} else {
   echo "The email($email_subject) was NOT sent.";
?>

此外,您在 if 条件之前有一个额外的行,如下所示。如果没有使用,请评论它。

(mail($email, $email_subject, $lesson1);

【讨论】:

  • 非常感谢。但它仍然没有发送电子邮件:(它只是打印出电子邮件地址、文本区域和“电子邮件未发送”... :(
  • @Sharon - 在这种情况下,您需要检查您的邮件服务器错误日志以找出问题所在。您确实在运行此代码的机器上安装了邮件服务器,不是吗?
  • 我真的很抱歉成为一个新手..我正在使用 wordpress。我需要添加任何东西才能拥有邮件服务器吗?
  • 我认为你应该去管理面板并编辑邮件服务器 SMTP 设置
猜你喜欢
  • 2012-07-02
  • 2022-01-13
  • 1970-01-01
  • 2011-05-21
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
  • 2021-11-06
  • 2016-03-10
相关资源
最近更新 更多