i am using encodeURIComponent to send value to php script
?txtAra = encodeURIComponent($("#textAra").val())
I saw in firebug it sends line break as %0A, in php script i am using
$txtA = $_POST['txtAra'];
and php mail function, in email i sees as test\n\n\ntest\n\n\ntest
How do i make \n as normal line break in mail?
i tried str_replace and nl2br, still same.
Any idea why?
What header type you are setting in mail ?
text
or html ?
Related
I have a site where anyone can leave comments.
By leaving a comment browser makes an ajax request to PHP script, sending encodeURIComponent-ed data to PHP script.
Earlier, in the PHP script, I added
$data = str_replace("\n","\\n",str_replace("\"","\\\"",$_POST["text"]));
Now I’ve been testing by inputting random stuff and found an exploit: if to input %00, it will be added to my comments file as null-terminator and corrupts my data. Also, other percent-encoded value will be decoded.
I am sending data as a regular application/x-www-form-urlencoded.
How to fix that?
So, the solution I’ve made so far is:
$_POST["text"] = str_replace("\"","\\\"",$_POST["text"]);
for($i=0;$i<=40;$i++)
if(chr($i)!="\n"&&chr($i)!="\r"&&chr($i)!=" "&&chr($i)!="("&&chr($i)!="&"&&chr($i)!="!"&&chr($i)!="\""&&chr($i)!="'")
$_POST["text"] = str_replace(chr($i),"",$_POST["text"]);
$_POST["text"] = str_replace("\\","",$_POST["text"]);
It just removes all special and potentially malware non-readable characters with some exceptions (newlines, ampersands etc.).
The only issue of this solution is that it removes backslash (but successfully writes data).
I have a variable say $message which contains the content to be sent in mail using php mail function. This variable $message will contain text that will also have line breaks. This variable data is being fetched from textarea of another file using ajax.
For instance, the actual text is:
Hello
This is a test message
So while sending mail ($message variable), I see Hello This is a test message, without line break. Is there a way to fix this?
You can use like that:
$message = str_replace ('<br>' , '\r\n', $_POST['textarea']);
You can also use nl2br() function here.
Make sue you are using HTML header in mail() function.
Very simply, i want to make a variable reads the html code as string ,, i mean dont execute it (run it) .
the problem with the code is : i have a html file , and i want to get the content of it , and make some preg_replace for it (run a function on the html code), the problem is i cant use preg_replace, or any another function because the html code is executed by php (php reads the html code)..
i wish you understand me, i want something like highlight_string, but it save the html code in the variable.
Thank you.
you're probably trying to include or require the HTML code.
which is incorrect since it is evaluated as part of the source.
instead, use a function such as file_get_contents() to read the file into a string.
Use file_get_contents() as #David Chan suggested and then pass the result through htmlentities()... it converts the characters to HTML entities (i.e., < to <).
$getTheContent = file_get_contents($filepath);
echo htmlentities($getTheContent);
It should return the code, not executed.
I have wrote a simple php script which reads an IMAP email account and displays the body of the most recent mail. There is just one problem, it won't keep the new lines properly. It just puts it all on one line.
I use
imap_fetchbody($conn, $latest, "1");
to read the body of the email. How do I keep the original formatting with all the proper line breaks. Much thanks
Are you outputting to a browser? Try using nl2br. The doc says:
Inserts HTML line breaks before all
newlines in a string
Example:
<?php
echo nl2br("foo isn't\n bar");
//output: foo isn't<br /> bar
?>
Why don't you try the print_r option which is in built in PHP?
I'm using PHP _EOL when building the message body of my email but the line feeds are not getting through and the entire message body ends up one long line in the resultant email. This happens regardless of Multi-part or html only messages. Sending as text only it works fine, but of course I want to send Multi-part messages.... Any ideas?
Uhm. If there are no line breaks in your HTML email, it's probably because neither a \n nor a \r\n is a newline in HTML; a <br /> tag is.
I've never even used PHP_EOL before, but I wonder if it is set to the type of your server, not of the recipient. I don't see how a constant could be correct for all recipients, that doesn't make sense.
Usually '\n' is all that is needed... in some cases you may need '\r\n' depending on the protocol involved. What are you using to send the email? What are you using to view the email?