Jump to content

Recommended Posts

So i've been getting this problem when using a  contact form. For some reason i keep getting those n\r\ which i'm prety sure it stands for line breaks. I've tried using everything that i can think to get rid of them, but the only thing that seems to work is if i remove the stripslashes() from it, the issue with that is that if someone types 'i'm' it will display i\m.

 

 

Link to comment
https://forums.phpfreaks.com/topic/206815-cant-get-rid-of-nr-symbols/
Share on other sites

Could you post your code?

 

And for the problem with the I'm and that sort of thing with quotes inside of user submitted forms to fix it place your $_POST[''] and any other code around that inside of this mysql_real_escape_string()

 

so for example it may look like this:

 

mysql_real_escape_string(ucwords(strip_tags($_POST['name'])));

Sorry, i should now by now that i need to place the code

 


if(isset($_POST['send'])){
        $name = mysql_real_escape_string(stripslashes($_POST['name']));
$message = mysql_real_escape_string(stripslashes($_POST['message']));

$insert_leads = "INSERT INTO leads (full_name, message) 
			VALUES('$name',  '$message')";	
$run_insert = mysql_query($insert_leads) or die(mysql_error());

$to = ''.$admin_email.'';
$subj = 'New contact submission';
$from = 'From:noreply@domain.com';
$body = '
	The following lead was submited on '.$date_added.' from ip: '.$ip.':

	Name:'.$name.'
	Message:

		'.$message.'
';

mail($to, $subj, $body, $from);

$msg ='
	<h2>Your message has been sent</h2>
								';
}
}

 

I've also used nl2br so i can add line breaks where ever the user skips a line. The funny thing is that i've used this on same format on other

forms and submitted them the same and never had that issue

once again sorry,

 

well say the user types in a message in the message textbox using a form, and adds a bunch of line breaks..(or just presses enter to many times)

 

when it gets mailed to my email address each line break will be displayed as n\r\ and so on..

 

as far as the quotations, well keeping the mysql_real_escape_string(stripslashes()) fixes the that problem, but once i

remove it it fixes the n\r\ problem but obviously the quotations don't show up

 

do i make sense??

what if i used two variables to hold the message data..one that would go into the database and the other that will output the data? could that fix the problem

try this

 

<?php
if(isset($_POST['send'])){
$dbname = mysql_real_escape_string(stripslashes($_POST['name']));
$dbmessage = mysql_real_escape_string(stripslashes($_POST['message']));
$name = stripslashes($_POST['name']);
$message = stripslashes($_POST['message']);
$insert_leads = "INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')";
$run_insert = mysql_query($insert_leads) or die(mysql_error());

	$to = $admin_email;
	$subj = 'New contact submission';
	$from = 'From:noreply@domain.com';
	$body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.'';

		mail($to, $subj, $body, $from);
		$msg ='<h2>Your message has been sent</h2>';
}}

what if i used two variables to hold the message data..one that would go into the database and the other that will output the data? could that fix the problem

try this

 

<?php
if(isset($_POST['send'])){
$dbname = mysql_real_escape_string(stripslashes($_POST['name']));
$dbmessage = mysql_real_escape_string(stripslashes($_POST['message']));
$name = stripslashes($_POST['name']);
$message = stripslashes($_POST['message']);
$insert_leads = "INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')";
$run_insert = mysql_query($insert_leads) or die(mysql_error());

	$to = $admin_email;
	$subj = 'New contact submission';
	$from = 'From:noreply@domain.com';
	$body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.'';

		mail($to, $subj, $body, $from);
		$msg ='<h2>Your message has been sent</h2>';
}}

 

I actually just noticed that this won't work at all how i initially thought, you would have to fetch the data from the database to send via email

(I'm not the best at fixing code when i cannot view the results step by step myself, sorry about that)

 

What i think may work is something like this:

 

<?php
if(isset($_POST['send'])){
$dbname = mysql_real_escape_string(stripslashes($_POST['name']));
$dbmessage = mysql_real_escape_string(stripslashes($_POST['message']));
$query = mysql_query("SELECT * FROM leads WHERE full_name='$dbname', message='$dbmessage'");
$sel = mysql_fetch_assoc($query);
$name = $sel['full_name'];
$message = $sel['message'];
$run_insert = mysql_query("INSERT INTO leads (full_name, message) VALUES('$dbname','$dbmessage')") or die(mysql_error());

	$to = $admin_email;
	$subj = 'New contact submission';
	$from = 'From:noreply@domain.com';
	$body = 'The following lead was submited on '.$date_added.' from ip: '.$ip.': Name:'.$name.' Message:'.$message.'';

		mail($to, $subj, $body, $from);
		$msg ='<h2>Your message has been sent</h2>';
}}

 

 

Post the results once you've tried everything out.

alright so i tried what @shortysbest said, and that seem to finally work.

 

one last final thing..does any one know why this would only happen on certain server i guess..because I've used that method before, using one variable to both carry the db data and email data and i've never had any issues up until now.

 

anyways thanks for the help

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.