【问题标题】:PHP email form is not adding the email submitted to my inboxPHP电子邮件表单未添加提交到我的收件箱的电子邮件
【发布时间】:2014-02-28 17:25:30
【问题描述】:

由于某种原因,当我在网站上的表单中提交电子邮件时,我没有看到它出现在我的收件箱中,它只是显示“电子邮件:”而没有添加电子邮件地址??!帮助

HTML

 <form method="POST" action="/subscribe.php">
      <input type="email" placeholder="Email" name="email">
      <input type="submit" value="submit" name="submit">
    </form>

这是我的 PHP 代码:

<?php

## CONFIG ##

# LIST EMAIL ADDRESS
$recipient = "domaininfo@gmail.com";

# SUBJECT (Subscribe/Remove)
$subject = "Notify me when you launch";

# RESULT PAGE
$location = "http://apple.com";

## FORM VALUES ##

# SENDER - WE ALSO USE THE RECIPIENT AS SENDER
# DON'T INCLUDE UNFILTERED USER INPUT IN THE MAIL HEADER!
# SEE ALSO: How to protect a php Email Form using php mail or mb_send_mail against Mail Header Injection
$sender = $recipient;

# MAIL BODY
$body .= "Name: ".$_REQUEST['Name']." \n";
$body .= "Email: ".$_REQUEST['Email']." \n";
# add more fields here if required

## SEND MESSGAE ##

mail( $recipient, $subject, $body, "From: $sender" ) or die ("Mail could not be sent.");

## SHOW RESULT PAGE ##

header( "Location: $location" );
?>

【问题讨论】:

  • 问题:为什么用 ruby​​-on-rails 标记?

标签: php html forms email


【解决方案1】:

不能混用

$_REQUEST['Email'] != $_REQUEST['email']

所以更改您输入的名称或更改您的请求。

&lt;input type="email" placeholder="Email" name="Email"&gt; -或- $_REQUEST['email']

【讨论】:

  • 非常感谢 cmorrissey 修复它!
【解决方案2】:

即使忽略了许多语法错误,例如:

  1. 在 $_REQUEST 中使用了错误的键,电子邮件的字段名称是小写的,因此在处理 PHP 脚本时它也应该是小写的。

  2. 表单中没有名为 Name 的字段,但您在处理脚本的 PHP 代码中使用它。

  3. 您应该检查表单是否提交,您可以这样做:

    if( isset($_POST['submit']) ) {
      //Code for handling
    }
    

我可能会列出很多可能出错的事情:

  1. 因为您是从本地机器/某个服务器发送电子邮件;很可能它将被视为垃圾邮件,您可能想查看您的垃圾邮件/垃圾邮件文件夹。

  2. 您在托管脚本的机器上没有安装(或工作)任何 SMTP 服务器。

【讨论】:

    【解决方案3】:

    不要混合大小写

    $_REQUEST['Email'] !=  $_REQUEST['email']
    

    所以更改您输入的名称或更改您的请求。

    <input type="email" placeholder="Email" name="Email"> -or- $_REQUEST['email']
    

    通过http://itspiders.net

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-16
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      相关资源
      最近更新 更多