简体   繁体   中英

PHP email form is not adding the email submitted to my inbox

For some reason when I submit an email in the form on the site I do not see it show up in my inbox it just says "Email:" with no email address added??! HELP

HTML

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

That's my PHP Code:

<?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" );
?>

You can't mix cases

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

so change the name on your input or change your request.

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

Even after ignoring many syntax errors such as:

  1. Using wrong keys in $_REQUEST, the name of the fields for email is in lower case, hence in handling PHP script also it should be in lowercase.

  2. There is no feild called Name in the form, but you are using it in PHP code which is handling your script.

  3. You should check wheather the form is submitted or not, you may do so as:

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

There could me many things which could be going wrong to list some:

  1. Since you are sending Email from a local machine/some server; most probably it will be treated as a SPAM, may be you would like to take a look into your Junk/Spam folder.

  2. You don not have any SMTP server installed(or working) on the machine where you are hosting your scripts.

Don't mix case letters

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

so change name on your input or change your request.

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

via http://itspiders.net

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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