Solved

php newslettter form

Posted on 2014-04-08
3
243 Views
Last Modified: 2014-04-25
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
Comment
Question by:leblanc
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
ID: 39993971
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
 
LVL 1

Author Comment

by:leblanc
ID: 39994024
MUA? MTA?
0
 
LVL 26

Expert Comment

by:skullnobrains
ID: 39995743
oups sorry : Mail Transfer/User Agent (aka mail server and mail client)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question