[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

php newslettter form

Posted on 2014-04-08
3
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
skullnobrains earned 2000 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 27

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

656 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