• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

php newslettter form

I got this simple code for the newsletter subscription. It sends me the email notification but the user's email is not displayed in the content of my email.

test.htm:
<form method="POST" action="enter the URL to your PHP page here">
<p>Name: <input type="text" name="Name" size="20"></p>
<p>Email: <input type="text" name="Email" size="20"></p>
<p><input type="submit" value="Submit" name="Submit"></p>
</form>

Open in new window


mailer.php:
<?php

## CONFIG ##

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

# SUBJECT (Subscribe/Remove)
$subject = "Subscribe";

# RESULT PAGE
$location = "enter the URL of the result page here";

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

Open in new window

0
leblanc
Asked:
leblanc
  • 2
1 Solution
 
skullnobrainsCommented:
code looks good unless i missed something.

but you do not check wether the user actually typed anything in the email field. it seems likely that most users will not fill their email if they are not compelled into doing so.

try this dumb check : replace
$body .= "Email: ".$_REQUEST['Email']." \n";

with
$body .= "Email: ".($_REQUEST['Email']?$_REQUEST['Email']:"empty")." \n";

also note that line endings should be \r\n for email transfer and long addresses may exceed the allowed line length... but i don't think it will actually produce a problem unless you have a VERY restrictive MUA or MTA
0
 
leblancAccountingAuthor Commented:
MUA? MTA?
0
 
skullnobrainsCommented:
oups sorry : Mail Transfer/User Agent (aka mail server and mail client)
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now