Author Topic: PHP Mailform doesnt like SPACES in text boxes  (Read 763 times)

0 Members and 1 Guest are viewing this topic.

Offline WolfRage

  • Devotee
  • Posts: 651
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #15 on: February 09, 2010, 08:40:23 AM »
To fix the spaces problem, use the function trim(). So enclose your variables in trim when you create them like so:
<?php
$httpref
=trim($_POST['httpref']); 
?>

Well now we know all of the data is getting passed correctly.
 
I also noticed that some of your varibales are setup incorrectly; for instance you are traping the same $_POST variable and labling it as a different variable.
<?php
$song5 
$_POST['song3'];
//Should be
$song5 $_POST['song5'];
?>

You also did this same exact thing on several songs and artists.
 
You attempted to echo a variable that does not exist here:
<?php 
echo $visitormail 
//Should be
echo $email 
?>

 
The following variables were never defined: $todayis, $attn, $notesout.
 
According to your last print out of your script you never call the mail() function, thus no email is ever sent.
 
According to your var_dump() your form is not defining: ip, httpref, httpagent.
 
So that is quite a list of corrections to be made, unless you did not post all of your script.
If you need help making these, please post back with as many corrections as you can make and we will go from there.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
Please be forewarned; rather than giving you exactly what you want I prefer to teach you how to get what you want. Knowledge is power, so take the time to learn PHP and you will be able to wield it's power.
If I just gave you the code to solve your problem then you will be back again tomorrow asking for more of the same code. So please take the time to learn. Thanks.

Offline dandaman2010Topic starter

  • Irregular
  • Posts: 11
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #16 on: February 10, 2010, 04:05:52 AM »
Hi WolfRage,

thanks for all your help.

I did however managed to have a play around and get this to work...... please see the working code below.

Thanks again, appreciated.

Dan

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"

<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<
title>Sendemail Script</title>
</
head>
<
body>

<!-- 
ReminderAdd the link for the 'next page' (at the bottom) --> 
<!-- 
ReminderChange 'YourEmail' to Your real email --> 

<?
php
$ip 
$_POST['ip']; 
$httpref $_POST['httpref']; 
$httpagent $_POST['httpagent']; 
$visitor $_POST['visitor'];
if (!
$_POST['visitor']) {
	
$visitor $_POST['name'];
}
$visitor2 $_POST['visitor2']; 
$group1 $_POST['group1']; 
$group2 $_POST['group2']; 
$dietary $_POST['dietary']; 
$dietary2 $_POST['dietary2']; 
$artist $_POST['artist']; 
$artist2 $_POST['artist2']; 
$artist3 $_POST['artist3']; 
$artist4 $_POST['artist4']; 
$artist5 $_POST['artist5']; 
$song $_POST['song']; 
$song2 $_POST['song2']; 
$song3 $_POST['song3']; 
$song4 $_POST['song4']; 
$song5 $_POST['song5']; 
$name $_POST['name']; 
$email $_POST['email']; 
$comments $_POST['comments']; 

$subject Wedding

$message "
From: 
$visitor \n
Are they coming to the wedding?: 
$group1 \n
Dietary: 
$dietary \n

From: 
$visitor2 \n
Are they coming to the wedding?: 
$group2 \n
Dietary: 
$dietary2 \n

Artist1: 
$artist \n
Song1: 
$song \n

Artist2: 
$artist2 \n
Song2: 
$song2 \n

Artist3: 
$artist3 \n
Song3: 
$song3 \n

Artist4: 
$artist4 \n
Song4: 
$song4 \n

Artist5: 
$artist5 \n
Song5: 
$song5 \n


------------------CONTACT US FORM-----------------------------


Contact Us Name: 
$name \n
Contact Us Email part1: 
$email \n

Contact Us comments: 
$comments \n

"
;

$visitor_fn_sn explode(" ",$visitor);
$sender_name $visitor_fn_sn[0].$visitor_fn_sn[1].$visitor_fn_sn[2].$visitor_fn_sn[3];

$from "From: $sender_name \r\n";


mail("********@hotmail.com"$subject$message$from);

?>

<p align="center">
<script>location.href="thankyou.html";</script><BR>
<a href="thankyou.html"><b>Thankyou</b></a> 

Date: <?php echo $todayis ?> 
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
<br />

Attention: <?php echo $attn ?>
<br /> 
Message:<br /> 
<?php $notesout str_replace("\r""<br/>"$notes); 
echo 
$notesout?> 
<br />
<?php echo $ip ?> 

<br /><br />
<a href="contact.php"> Next Page </a> 
</p> 

</body>
</html>



Offline WolfRage

  • Devotee
  • Posts: 651
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #17 on: February 10, 2010, 06:49:49 AM »
OK now that it is working lets add some protection. First you should start by surrounding all of your $_POST elements in the function htmlspecialchars(). This will html encode any links or other html that spam bots might try to inject into your form which then sends you an email. Example:
<?php
$visitor
=htmlspecialchars(trim($_POST['name']));
?>

Next you may want to prevent spam bots all together by asking a question on your form with a single one word asnwer and if the user does not reply correctly then their message will be rejected. Just make sure to account for upper and lower case answers by using the function strtolower(). Simple question example could be "What is the second letter of the english alphabet?"
 
One more thing if in the future you ever make another script that recieves and or acts on input from a user make sure to filter the data before you use it.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
Please be forewarned; rather than giving you exactly what you want I prefer to teach you how to get what you want. Knowledge is power, so take the time to learn PHP and you will be able to wield it's power.
If I just gave you the code to solve your problem then you will be back again tomorrow asking for more of the same code. So please take the time to learn. Thanks.