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

0 Members and 1 Guest are viewing this topic.

Offline dandaman2010Topic starter

  • Irregular
    • View Profile
PHP Mailform doesnt like SPACES in text boxes
« on: February 08, 2010, 07:21:53 AM »
Hi all,

I'm having some strange trouble with a PHP Mailform script that i'm hoping someone can help me out with.

The website is http://www.scottandbottietheknot.co.uk/ - on the site are 2 mail form scripts. 1 on the homepage, and the other on the RSVP page.

Now the form on the homepage works fine - ignore this form. Its the form on the RSVP page that isn't behaving properly.

(BTW both forms us the same php mail script)

On the RSVP page, if i submit a form with text elements WITH NO SPACES in them, the form submits fine, and the data is e-mailed to the relevant e-mail address. However, if i put in for example "John Doe" in the text box (note the space in the string) then the form doesn't submit.

The really strange thing, is that SPACES DO WORK on the homepage form. As mentioned both pages use the same script, so i don't know how this is even possible or how to fix it.

Please could someone help.

Thanks
Dan

Offline dandaman2010Topic starter

  • Irregular
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #1 on: February 08, 2010, 08:18:40 AM »
Thought i would post the code in on the php mail form script.


<!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']; 
$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['artist3']; 
$artist5 $_POST['artist3']; 
$song $_POST['song']; 
$song2 $_POST['song2']; 
$song3 $_POST['song3']; 
$song4 $_POST['song3']; 
$song5 $_POST['song3']; 
$name $_POST['name']; 
$email $_POST['email']; 
$comments $_POST['comments']; 

$subject Wedding

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

From: 
$visitor2 \n
Are they comming 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


"
;

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


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

?>

<p align="center">
<script>location.href="thankyou.html";</script><BR> 
<a href="thankyou.html"><b></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
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #2 on: February 08, 2010, 08:20:48 AM »
To make sure that everything is coming out as you expect it to echo it all out and make sure that everything you expect is really there. Also turn on Error Reporting.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
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
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #3 on: February 08, 2010, 08:23:09 AM »
Hi WolfRage,

Thanks for the reply. I'm not a PHP expert, so am not familiar with the term ECHO, please could you explain.

Also, i don't have access to the server logs - just FTP access.

Thanks
Dan

Offline WolfRage

  • Devotee
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #4 on: February 08, 2010, 08:47:30 AM »
Ok first some basics, any time you see something with a $ sign starting it, that is refered to as a variable. 'echo' is a PHP construct, meaning it is built in to the langauge as a method for outputing a variable; only applicable for strings, integers, and floating types.
So what you need to do is echo each variable that is being defined.
Example:
 <?php
 
[color=#0000bb]$ip [/color]= $_POST['ip']; 
echo 'ip='.$ip.'<br>';
$httpref $_POST['httpref']; 
echo 
'httpref='.$httpref.'<br>';
$httpagent $_POST['httpagent']; 
echo 
'httpagent='.$httpagent.'<br>';
?>

By doing this you can see if you are getting all of the varibles defined correctly and you can make sure they are right.
 
To turn on error reporting put this at the top of the script.
<?php
 
[font=consolas]// Report all PHP errors (see changelog)
error_reporting(E_ALL[/font][font=consolas]);[/font]

?>

Once you have gotten this far we can find the problem and then once we fix the problem we can go about making this form more secure so that you are not getting spamed to all hell.
Ok sorry for being incomplete but I have to go for now.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
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
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #5 on: February 08, 2010, 09:13:25 AM »
Not sure i'm doing this correctly as its not showing me anything....
<!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
 
[font=consolas]// Report all PHP errors (see changelog)
error_reporting(E_ALL[/font][font=consolas]);[/font]

?>


 <?php
 
[color=#0000bb]$ip [/color]= $_POST['ip']; 
echo 'ip='.$ip.'<br>';
$httpref $_POST['httpref']; 
echo 
'httpref='.$httpref.'<br>';
$httpagent $_POST['httpagent']; 
echo 
'httpagent='.$httpagent.'<br>';
$visitor $_POST['visitor']; 
echo 
'visitor='.$visitor.'<br>';
$visitor2 $_POST['visitor2']; 
echo 
'visitor2='.$visitor2.'<br>';
$group1 $_POST['group1']; 
echo 
'group1='.$group1.'<br>';
$group2 $_POST['group2']; 
echo 
'group2='.$group2.'<br>';
$dietary $_POST['dietary']; 
echo 
'dietary='.$dietary.'<br>';
$dietary2 $_POST['dietary2']; 
echo 
'dietary2='.$dietary2.'<br>';
$artist $_POST['artist']; 
echo 
'artist='.$artist.'<br>';
$artist2 $_POST['artist2']; 
echo 
'artist2='.$artist2.'<br>';
$artist3 $_POST['artist3']; 
echo 
'artist3='.$artist3.'<br>';
$artist4 $_POST['artist3']; 
echo 
'artist4='.$artist4.'<br>';
$artist5 $_POST['artist3']; 
echo 
'artist5='.$artist5.'<br>';
$song $_POST['song']; 
echo 
'song='.$song.'<br>';
$song2 $_POST['song2']; 
echo 
'song2='.$song2.'<br>';
$song3 $_POST['song3']; 
echo 
'song3='.$song3.'<br>';
$song4 $_POST['song3']; 
echo 
'song4='.$song4.'<br>';
$song5 $_POST['song3']; 
echo 
'song5='.$song5.'<br>';
$name $_POST['name']; 
echo 
'name='.$name.'<br>';
$email $_POST['email']; 
echo 
'email='.$email.'<br>';
$comments $_POST['comments']; 
echo 
'comments='.$comments.'<br>';
?>

$subject = Wedding; 

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

From: $visitor2 \n
Are they comming 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


";

$from = "From: $visitor\r\n";


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

?>

<p align="center">
<script>location.href="thankyou.html";</script><BR> 
<a href="thankyou.html"><b>The new Toshiba Mini NB300/NB305 Netbooks</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
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #6 on: February 08, 2010, 09:25:17 AM »
Ok after looking it over if you are not getting anything then, the problem is not the script it is your form. So please post the source code for your form, so that we can find out why. Also please give the url of the form and the PHP script as they are on your server.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
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
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #7 on: February 08, 2010, 09:32:09 AM »
The RSVP form in question is located here......

http://www.scottandbottietheknot.co.uk/RSVP.html
Code: [Select]
<html>
<head>
<title>Chris and Rachels Wedding &gt; RSVP</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="robots" content="noindex,nofollow">
 
<script type="text/javascript">
<!-- //start
 
//######################################################################################
// Author: ricocheting.com
// For: public release (freeware)
// Date: 4/24/2003 (update: 5/15/2009)
// Description: displays the amount of time until the "dateFuture" entered below.
 
 
// NOTE: the month entered must be one less than current month. ie; 0=January, 11=December
// NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm
 
dateFuture = new Date(2010,6,2,13,0,0);
 
// TESTING: comment out the line below to print out the "dateFuture" for testing purposes
//document.write(dateFuture +"<br />");
 
 
//###################################
//nothing beyond this point
function GetCount(){
 
dateNow = new Date(); //grab current date
amount = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;
 
// time is already past
if(amount < 0){
document.getElementById('countbox').innerHTML="Now!";
}
// date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";
 
amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
 
days=Math.floor(amount/86400);//days
amount=amount%86400;
 
hours=Math.floor(amount/3600);//hours
amount=amount%3600;
 
mins=Math.floor(amount/60);//minutes
amount=amount%60;
 
secs=Math.floor(amount);//seconds
 
if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
out += secs +" seconds";
document.getElementById('countbox').innerHTML=out;
 
setTimeout("GetCount()", 1000);
}
}
 
window.onload=GetCount;//call when everything has loaded
 
//-->
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="1024" height="695" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td rowspan="2">
<img src="images/Blog_01.jpg" width="134" height="92" alt=""></td>
<td colspan="8" width="774" height="64" background="images/HomePage_02.jpg">
        <div id="countbox" style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:13px; font-weight:bold; text-align:center; color:#764C6E; padding-left:480px;"></div>
            <div style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:11px; text-align:center; color:#764C6E; padding-left:500px;">until the wedding begins</div>
        </td>
<td rowspan="2">
<img src="images/Blog_03.jpg" width="116" height="92" alt=""></td>
</tr>
<tr>
<td><a href="index.html"><img src="images/Blog_04.jpg" alt="" width="83" height="28" border="0"></a></td>
<td><a href="aboutus.html"><img src="images/Blog_05.jpg" alt="" width="89" height="28" border="0"></a></td>
<td><a href="weddingparty.html"><img src="images/Blog_06.jpg" alt="" width="125" height="28" border="0"></a></td>
<td><a href="engagement.html"><img src="images/Blog_07.jpg" alt="" width="119" height="28" border="0"></a></td>
<td><a href="RSVP.html"><img src="images/Blog_08.jpg" alt="" width="66" height="28" border="0"></a></td>
<td><a href="venues.html"><img src="images/Blog_09.jpg" alt="" width="85" height="28" border="0"></a></td>
<td><a href="weddinglist.html"><img src="images/Blog_10.jpg" alt="" width="98" height="28" border="0"></a></td>
<td><a href="http://scottandbottietheknot.co.uk/blog/"><img src="images/Blog_11.jpg" alt="" width="109" height="28" border="0"></a></td>
</tr>
<tr>
<td>
<img src="images/Blog_12.jpg" width="134" height="318" alt=""></td>
<td colspan="8" rowspan="2" width="774" height="603" background="images/Blog_13.jpg" valign="top" align="left" style="padding-top:10px; padding-left:10px;">
        <h1>RSVP</h1>
        <p>Please complete the relevant fields below which will save you sending back the tag in the post. You can also request songs for the evening entertainment using the form below, which can be independent of the RSVP. If you can&acute;t remember your favourite Scorpions song, then please RSVP now and return later to post your song requests. There is no limit to the number you can choose, although the disco doesn&acute;t run all night.
        <br>
        <br>
        <b>Please RSVP by 1st May 2010. No reply; no entry.</b></p>
 
       
       
<form method="post" action="sendeail.php">
 
<!-- DO NOT change ANY of the php sections -->
 
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
 
<table width="750" border="0" cellspacing="0" cellpadding="4" align="left">
  <tr>
    <td width="182" style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;">Full Name</td>
    <td width="152" style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;">Will be delighted to accept</td>
    <td width="142" style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;">Regretfully can not accept</td>
    <td width="172" style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;">Dietary requirements?</td>
  </tr>
  <tr>
    <td><input type="text" name="visitor" size="25" /></td>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFF"><input type="radio" name="group1" value="yes" checked /></td>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFF"><input type="radio" name="group1" value="no" /></td>
    <td><input type="text" name="dietary" size="25" /></td>
  </tr>
  <tr>
    <td><input type="text" name="visitor2" size="25" /></td>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFF"><input type="radio" name="group2" value="yes" checked /></td>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#FFF"><input type="radio" name="group2" value="no" /></td>
    <td><input type="text" name="dietary2" size="25" /></td>
  </tr>
<tr>
<td colspan="4"><h2>&nbsp;</h2></td>
</tr>
<tr>
<td colspan="4"><h2>Any song requests? Enter them here!</h2></td>
</tr>
<tr>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;" colspan="2">Artist</td>
    <td style="font:Arial, Helvetica, sans-serif; font-family:Arial, Helvetica, sans-serif; font-size:10px;" colspan="2">Song</td>
  </tr>
  <tr>
    <td colspan="2"><input type="text" name="artist" size="25" /></td>
    <td colspan="2"><input type="text" name="song" size="25" /></td>
</tr>
 <tr>
    <td colspan="2"><input type="text" name="artist2" size="25" /></td>
    <td colspan="2"><input type="text" name="song2" size="25" /></td>
</tr>
 <tr>
    <td colspan="2"><input type="text" name="artist3" size="25" /></td>
    <td colspan="2"><input type="text" name="song3" size="25" /></td>
</tr>
 <tr>
    <td colspan="2"><input type="text" name="artist4" size="25" /></td>
    <td colspan="2"><input type="text" name="song4" size="25" /></td>
</tr>
 <tr>
    <td colspan="2"><input type="text" name="artist4" size="25" /></td>
    <td colspan="2"><input type="text" name="song4" size="25" /></td>
</tr>
<tr>
<td colspan="4" align="center" valign="bottom"><input type="submit" value="Send Mail" /></td>
</tr>
</table>
</form>
       
       
       
       
        </td>
<td rowspan="2">
<img src="images/Blog_14.jpg" width="116" height="603" alt=""></td>
</tr>
<tr>
<td>
<img src="images/Blog_15.jpg" width="134" height="285" alt=""></td>
</tr>
</table>
</body>
</html>


The PHP script can be located here - http://www.scottandbottietheknot.co.uk/sendeail.php

Thanks again
Dan

Offline dandaman2010Topic starter

  • Irregular
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #8 on: February 08, 2010, 11:10:59 AM »
bump

Offline dandaman2010Topic starter

  • Irregular
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #9 on: February 08, 2010, 01:26:30 PM »
Hi all,

I could really do with some help tonight please? I need to get this sorted asap.

Thanks
Dan

Offline dandaman2010Topic starter

  • Irregular
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #10 on: February 09, 2010, 04:15:27 AM »
anyone?

Offline WolfRage

  • Devotee
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #11 on: February 09, 2010, 06:08:54 AM »
SO looking it over your form looks to be ok. SO lets do something a little different. Add to the mail script the following:
 <?php
var_dump
($_POST);
?>

Let me know what that spits out, this should also give you a lot of information to figure out what is going on. Make sure you use th form to submit your request to the mail script. If all else fails, PM me your email address and I will go to the site tonight and help you out via email.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
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
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #12 on: February 09, 2010, 06:42:10 AM »
Hi WolfRage,

I really appreciate your help. Thanks

Does that bit of script just go to the top of the script or replace the script itself?

Thanks
Dan

Offline WolfRage

  • Devotee
  • Gender: Male
    • View Profile
    • Feral Bytes
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #13 on: February 09, 2010, 06:46:50 AM »
Just put it at the top, and it should dump the entire contents of the $_POST array. Then we can decide if the data is getting from the form to the script.
-- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * -- * --
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
    • View Profile
Re: PHP Mailform doesnt like SPACES in text boxes
« Reply #14 on: February 09, 2010, 07:00:51 AM »
Hi WolfRage,

Thanks again - Here is what the output was.

array(19) { ["ip"]=> string(18) "" ["httpref"]=> string(23) "" ["httpagent"]=> string(25) "" ["visitor"]=> string(16) "Full name test 1" ["group1"]=> string(3) "yes" ["dietary"]=> string(27) "Dietary requirements test 1" ["visitor2"]=> string(16) "Full name test 2" ["group2"]=> string(3) "yes" ["dietary2"]=> string(27) "Dietary requirements test 2" ["artist"]=> string(13) "Artist test 1" ["song"]=> string(11) "song test 1" ["artist2"]=> string(13) "Artist test 2" ["song2"]=> string(11) "song test 2" ["artist3"]=> string(13) "Artist test 3" ["song3"]=> string(11) "song test 3" ["artist4"]=> string(13) "Artist test 4" ["song4"]=> string(11) "song test 4" ["artist5"]=> string(13) "Artist test 5" ["song5"]=> string(11) "song test 5" }

Seems like everything is being past through ok...... the data just isnt being sent to the e-mail address when there are spaces in the text boxes.

Thoughts?
« Last Edit: February 09, 2010, 07:02:58 AM by dandaman2010 »

Offline WolfRage

  • Devotee
  • 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
    • 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
  • 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.

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.