PDA

View Full Version : form email php Bare LFs


miamikrock
06-10-2009, 02:51 PM
I'm having trouble with the form being emailed, I get an error saying I have bare LFs, the error said it was on line 39. I used the php tutorial from dreamweaver club.



<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'drgreenthumblawns@hotmail.com';

// Where to redirect after form is processed.
$url = 'http://greenthumblandscapingservice.com/contactconfirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

MagicPower
06-10-2009, 09:02 PM
bare linefeed (BARE LF) may be or is in the email body. some email servers or your web hosting sever doesn't allow BARE LF. for more infoe: http://cr.yp.to/docs/smtplf.html

miamikrock
06-10-2009, 09:23 PM
I've already been to that site, it didn't help me remedy the problem.

MagicPower
06-10-2009, 10:28 PM
i read some where that if you can edit the email body, you can fix the issue by replacing bare LF with CRLF. May i suggest Lightform its a free ajax/php contact form. i used it for my site (http://www.oed4u.com/contact/) check it out. if you are in any doubt if it works or not mail me off my site n i'll tell you ur message.

miamikrock
06-10-2009, 10:55 PM
I don't doubt you I just want to fix the php script. Can you paste the script here?

MagicPower
06-10-2009, 11:06 PM
i'm not a php scripter, i can try my best to help you. have you got this file class.usermailer.php

miamikrock
06-10-2009, 11:21 PM
no I do not.

edbr
06-11-2009, 01:36 AM
try replacing
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';


with
mail($emailadd, $subject, $text, 'From: '.$emailadd);
header( 'Location: 'http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;

miamikrock
06-11-2009, 03:03 AM
when I replaced the code, this is the error I recieved:

Parse error: syntax error, unexpected T_STRING
on line 40

Line 40 is:

header( 'Location: 'http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;

edbr
06-11-2009, 04:36 AM
ok just to try debugging, comment it out. that will disable the redirect for now. and try if mail is being sent
//header( 'Location: 'http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;

edbr
06-11-2009, 04:46 AM
whoops :(
header( 'Location: http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;

MagicPower
06-11-2009, 04:54 AM
Worry no mo miamikrock. this code should work i have tested it. you can also test the form on my site. (http://www.oed4u.com/testing/Dr.%20Green%20Thumb.htm) Let me know with your results.

Ma Bad, i forgot to post the code. Here it z.

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'mpaliguma@yahoo.com';

// Where to redirect after form is processed.
$url = 'http://greenthumblandscapingservice.com/contactconfirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, $emailadd);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>
replace: mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

with: mail($emailadd, $subject, $text, $emailadd);

miamikrock
06-11-2009, 07:02 AM
Ok I tried both of your solutions independantly and no luck but when I combine the two all error messages go away but I still do not recive any email from the form.

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'drgreenthumblawns@hotmail.com';

// Where to redirect after form is processed.
$url = 'http://greenthumblandscapingservice.com/contactconfirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, $emailadd);
header( 'Location: http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;
?>

MagicPower
06-11-2009, 10:40 AM
Go here n give it a try,
http://www.oed4u.com/testing/

but I still do not recive any email from the form.

is this the email drgreenthumblawns@hotmail.com you want to receive the information from the form

edbr
06-11-2009, 10:52 AM
as its a hotmail address, check your bulk / junk folders this type of mail sometimes finds its way there

miamikrock
06-11-2009, 01:44 PM
Magic Power, I got the form email from you, but when I put in the code that you used I get the original error of bare LFs. Could it be my hosting site: GoDaddy.

MagicPower
06-11-2009, 02:03 PM
it could probably be, check with them and see if your hosting that you bought off them has got php language support or any other that you may need in the future

miamikrock
06-11-2009, 02:36 PM
It says they support php 5.

Which code gave me the email at Thu, 11 Jun 2009 04:12:42 +0100

code 1:

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'drgreenthumblawns@hotmail.com';

// Where to redirect after form is processed.
$url = 'http://greenthumblandscapingservice.com/contactconfirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, $emailadd);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>


or code 2:

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'drgreenthumblawns@hotmail.com';

// Where to redirect after form is processed.
$url = 'http://greenthumblandscapingservice.com/contactconfirmation.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, $emailadd);
header( 'Location: http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;
?>

code 1 gives me the bare LFs error, while code 2 gives me no errors but I don't recieve email from either.

miamikrock
06-11-2009, 02:41 PM
Here are the hosting settings

Hosting Type: Shared Hosting
.Net Runtime Version: ASP.Net 2.0/3.0/3.5
PHP Version: PHP 5.x
IIS Version: IIS 7.0

MagicPower
06-11-2009, 03:06 PM
code 2 coz i modified it from this mail($emailadd, $subject, $text, 'From: '.$emailadd.''); to mail($emailadd, $subject, $text, $emailadd); 'From: '.$emailadd." had to change to $emailadd); it must av been code 2 coz i tested it with my @ yahoo n it was around that time when i started figiting with it. have u got @ yahoo, try replacing the hotmail with the yahoo c if that makes a diff. 1 mo thing did you add this to the code: header( 'Location: http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;
?>

miamikrock
06-11-2009, 03:19 PM
code 2 was a mix of your code and edbr's code.
you gave me:
mail($emailadd, $subject, $text, $emailadd);

edbr gave me:
header( 'Location: http://greenthumblandscapingservice.com/contactconfirmation.html' ) ;

when you tested it I got the email at the @hotmail.com email address.
but I have not been able to replicate the results.

MagicPower
06-11-2009, 03:25 PM
use this

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'your_email_address_type_it_here';

// Where to redirect after form is processed.
$url = 'XXXXXXX';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, $emailadd);
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

the only things you should change in this one
your_email_address_type_it_here n XXXXXXX. that should work coz thats the code i used when testing with my @yahoo. give it a try.

miamikrock
06-11-2009, 03:43 PM
I tried that code and got the bare LFs error.

miamikrock
06-11-2009, 03:49 PM
when the email went through were you using internet explorer, google chrome, or firefox?

Corrosive
06-11-2009, 03:56 PM
when the email went through were you using internet explorer, google chrome, or firefox?

If magicpower got the code to work on his site and you didn't, using the same code, then this is an issue with your hosts. I used to have a fasthost account (the shame) and, although I paid for PHP support, I had to manually go and switch it on in my control panel. Contact your hosts.

MagicPower
06-11-2009, 04:01 PM
when the email went through were you using internet explorer, google chrome, or firefox?Firefox, i'll try other browsers. check drgreenthumblawns@hotmail.com c if u have n messages in junk.

miamikrock
06-11-2009, 04:56 PM
Magic Power,
I received all your test submissions. I just need to find out why godaddy is not letting the form work. I've been trying to figure out if the php is turned on and I can't figure it out.

Corrosive
06-11-2009, 05:03 PM
Some hosts let you use PHP but stop short of letting you send mail using it. It is to stop spammers really. Check not only that they let you use PHP but also if they let you use the mail function...It might be bad news :(

miamikrock
06-11-2009, 05:29 PM
When I checked their help site, this is the closest thing I could find...
but I could not find the file php.ini that they were talking about.

By default, Plesk sets PHP to "safemode" during installation. To take PHP out of "safemode," you need to remote connect to your dedicated server and modify the php.ini file on the server.

To Turn off PHP "safemode" in Windows
Using Remote Desktop Connection, log in to your server as an administrator.
Open c:\windowsphp.ini in Notepad.
Change the line safe_mode = on to safe_mode = off.
Save and close php.ini.
Once you have edited the file, you need to restart your Web server. You can restart your Web server using Plesk by selecting stop/start under the Server> Service Management section.