Solved

php newslettter form

Posted on 2014-04-08
3
241 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 38
Need to learn promise API 2 28
excel file 5 48
How can i compile this github project?? 2 44
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now