Solved

php newslettter form

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

864 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

18 Experts available now in Live!

Get 1:1 Help Now