Repeatedly Recieving Empty Mailing List Applications

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
QuestingCordiial
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 5:18 pm

Repeatedly Recieving Empty Mailing List Applications

Post by QuestingCordiial »

Hello everyone,

I have a form that is used to send somebody's email address to me in an email so that I can add them to a mailing list.

The problem is, that I keep receiving emails that have no data in them; they don't contain the email address of whoever filled out the form.

Here is the HTML for the form:

Code: Select all

<form id="myForm" name="myForm" method="post" action="http://www.eddiecole.com/joinMail.php" onsubmit="return validate_form();">
    <input style="width:200px;" id="emailbox" type="text" name="text_email" value="Type Email Address Here" onfocus="clear_textbox()"/>
    <input type="submit" value="Join Mailing List" />
</form>
and here is the PHP code responsible for collecting the information from the form and emailing it to me:

Code: Select all

<?php
    $emailContents = "This person has requested to be added to the mailing list: \n";
    $emailContents .= "<" . htmlspecialchars($_POST["text_email"]) . ">";
    if ( htmlspecialchars($_POST["text_email"]) == "" )
    {
        $emailContents .= "\n\nThe text field was empty." ;
    }
    mail("admin@eddiecole.com","MAILING LIST ADDITION", $emailContents);
    echo ("<center>Thankyou. Your email address has been registered.</center>");
?>
The emails I receive should look like:

This person has requested to be added to the mailing list:
<jsmith@email.com>


But instead the look like this:

This person has requested to be added to the mailing list:
<>


I have tried getting browser information using hidden input fields in the form, but the information from these fields never arrives either.

When I test the script using my own computer (and also a friend's computer with different OS and browser) the whole thing works just fine!

I am not sure where exactly the problem is here; code or something else, so I apologize if I've asked this question in the wrong place.

Thanks for any help : )
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Repeatedly Recieving Empty Mailing List Applications

Post by andym01480 »

What does the return validate_form() do? - try it without that - it may be that is faulty!

Validate server side - google for a regexp to check email address is valid. htmlspecialchars doesn't give you enough protection - it would be possible to email inject using hex codes...

I'd use single quotes inside $_POST too.
QuestingCordiial
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 5:18 pm

Re: Repeatedly Recieving Empty Mailing List Applications

Post by QuestingCordiial »

Here is the validate_form() function:

Code: Select all

function validate_form()
{
    valid = true;
    if ( document.myForm.emailbox.value =="" ) 
    {
        valid = false;
        alert ("Please enter an email address.");
    }
    return valid;
}
I have only recently added the validation function, this problem was the reason that I added it.

What do you mean by "email inject using hex codes"? Do you think the empty emails are generated by bots or by people? Because if they are bots then it is not really a problem, just an annoyance.

Yes I will change those double quotes to single quotes.

With the validation code, do you think it would be a good idea to limit the number of characters that can be entered?

Thanks for the reply.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: Repeatedly Recieving Empty Mailing List Applications

Post by andym01480 »

Lots of people turn javascript off - hackers and bots work round it by looking at your form and sending it without using it. M.H.O. waste of time for a simple form.

What you must do server side is "validate" only accept the submission if it is a valid email address. Then build the message and send. If not output the form again.

Something like this when you have added your bits and found an email checking script will work every time!
Can all be in one file too...

Code: Select all

 
<?php
function emailchecker()
{
//google for an email check script
{
 
if (emailchecker($_POST['email']))
{
$message="Someone has registered with {$_POST['email']}";//build your message
$headers="";//have the recommended headers from manual for from address etc
$to="your email address";
$subject=""//your subject
mail($to;$subject,$message,$headers) OR DIE ("Couldn't send email");
exit();
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']:?>" method="post">
Email address:<input type="text" name="email"/>
<input type="submit" name="submit" value="submit"/>
</form>
QuestingCordiial
Forum Newbie
Posts: 3
Joined: Thu Jan 15, 2009 5:18 pm

Re: Repeatedly Recieving Empty Mailing List Applications

Post by QuestingCordiial »

Yes that makes a lot of sense : )

Thanks a lot, I'll do that and then post back in a while to say whether or not it worked! Could be like a couple of weeks though, I don't know.

Thanks heaps for your help!
Post Reply