PHP Send multistring email - php

trying to use a EOD tag to send an email via PHP, heres my code:
The Code is too large, I pasted it on pastebin:
http://pastebin.com/KK3QZx6p
Dreamweaver has an error on line two and the actual browser reports an error on the last line (the script tag that includes jQuery)
I have tried backslashes and all, but the EOD tags are being syntax highlighted, is that maybe the issue?
I basically want to send an email, and the main body I want to be a html email, I know you can use the concatenation, although if there is a way to paste it in using a multiline string and send it, that would be great, although the EOD tag, simply isn't highlighting, like I have done something wrong
Error From Browser: Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /home/a8526867/public_html/index.php
Dreamweaver is erroring on the second line

Indeed, I guess '{' at the last row gives a problem. You might try to escape it. But anyway, I don't think it's a good idea to use js or jquery in an email.

Related

Two equal PHP statements giving different results?

I was doing some coding on my phone when I got this error:
Parse error: syntax error, unexpected '"log.txt"' (T_CONSTANT_ENCAPSED_STRING) in your code on line 15
This is the offending code:
$file = "log.txt";
Note that you have to copy this exactly to get this result. This is because when I retype it:
$file = "log.txt";
I get no error. The two lines are the same, except for one thing: the second space in the line is binary "10100000" in the crashing statement, but "00100000" in the retyped one.
So I suppose my editor screwed up in some mystical way I will probably never discover. But what I don't get is why does this bad character look exactly like a space (as opposed to something else or a �), and why does it cause this particular error as if I didn't properly open my string?
It's a non-breaking space character.
It probably came about as a result of copying the code in from a blog post or from Word, for example.
The interpreter is not able to parse it as a regular space, hence the error.

PHP end tag "?>" [duplicate]

This question already has answers here:
Why would one omit the close tag?
(14 answers)
Closed 9 years ago.
I've had an interesting phenomenon with a PHP end tag. I had a php file that was executed by an Ajax call. In the php file was included a php library file with assorted functions. When this library was included the php response included a bunch of blank lines. When I removed the end tag from the library this stopped happening.
Can anyone explain to me what going on here ?
This is well documented. From the PHP Manual:
The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.
Omitting the closing tag helps you prevent accidental whitespace or newlines from being added to the end of the file.
That's a core PHP feature: unlike other languages, you need to tag PHP code with a special tag (normally <?php) because everything else is considered literal output:
This is not PHP
<?php
echo 'This is PHP' . PHP_EOL;
?>
This is not PHP either
D:\tmp>php test.php
This is not PHP
This is PHP
This is not PHP either
Although the manual mentions HTML, PHP doesn't really know/care what content-type is outside its tags.
If you forget to close a PHP block when further stuff follows you normally get a syntax error:
This is not PHP
<?php
echo 'This is PHP' . PHP_EOL;
This is not PHP either
D:\tmp>php test.php
PHP Parse error: syntax error, unexpected 'is' (T_STRING) in D:\tmp\borrame.php on line 6
Blank lines are a sort of special case because they are valid and almost invisible in almost all languages (PHP, HTML, CSS, JavaScript...) so they often unnoticed.
Once you've removed the ?> tag, your literal blank lines have disappeared from the script output because they've become part of the PHP code (and, as such, they've started to get ignored).
Of course, blank lines are ignored by PHP but not necessarily by whatever you are generating which, as I said, does not need to be HTML: it can be a picture, a PDF document, an Excel spreadsheet. Bogus white lines can be easily avoided by not closing the last PHP block when it's the last part of the file.

finding wrong characters in javascript

Since I am about to write a small php-script I like to call to get all the javascript for my page, this leads to strange error on client side. The script does actually use an configuration xml-file and some xsl-stylesheets to generate an large Javascript string. Sometimes it happens that I get an 'unterminated String literal' error, sometimes an error rises that says: 'An attempt was made to use an object that is not, or is no longer, usable', just after the javascript executes an document.write operation.
Are there any resources, or is there any tutorial, just something that reveals about the traps of running into such problems when copying a bunch of javscript files into one String or file?
greetings philipp
EDIT::
the following error:
is thrown in an webpage that is delivered with content-type: 'application/xhtml+xml'. The actual generated Javascript looks like this:
source code generated
The script itself runs until the first document.write command is triggered.
It sounds like the strings are not escaped completely/correctly. If you take care of
escaping all apostrophes to \'
escaping all quotation marks to \"
escaping all line feeds to \n
you shouldn't have any errors.

PHP lines with XML cause unexpected '>' errors

When I set variables that include angle brackets (< >) or slashes I keep getting errors like the following (code simplified to focus on error):
Parse error: syntax error, unexpected '>' in D:\hosting\8499439\html\test.php on line 2
<?php
$xml = “<Request>\n”;
?>
I also run into a lot off issues with "unexpected T_String" errors that appear to be related.
I'm running PHP5 on a GoDaddy Windows Server.
What am I doing wrong? (I get the impression I need to to do something so that special characters can be handled in my PHP).
Thanks in advance.
Your quotes are curly quotes, not straight quotes, so PHP runs into an error processing them. A string can only be recognized with straight quotes.
Use the following code:
<?php
$xml = "<Request>\n";
?>
Assuming that you have the same error elsewhere, you can probably do a simple search-and-replace to fix the error: search for one of the curly quotes, replace with a straight quote. Repeat with the other curly quote. Make sure to check for straight quotes that may need to be escaped (for instance, something like "Mary said, "I like this."" would need to be escaped as "Mary said, \"I like this.\"")
mc10 is right.
Additionally I can say, there are only ""(double) and ''(single) quotes in PHP. I suggest you to read about differences between them.
I prefer using single quotes only to keep code clear.

Removing Break Lines

I've asked this question before but I didn't seem to get the right answer. I've got a problem with new lines in text. Javascript and jQuery don't like things like this:
alert('text
text);
When I pull information from a database table that has a break line in it, JS and jQuery can't parse it correctly. I've been told to use n2lbr(), but that doesn't work when someone uses 'shift+enter' or 'enter' when typing text into a message (which is where I get this problem). I still end up with separate lines when using it. It seems to correctly apply the BR tag after the line break, but it still leaves the break there.
Can anyone provide some help here? I get the message data with jQuery and send it off to PHP file to storage, so I'd like to fix the problem there.
This wouldn't be a problem normally, but I want to pull all of a users messages when they first load up their inbox and then display it to them via jQuery when they select a certain message.
You could use a regexp to replace newlines with spaces:
alert('<?php preg_replace("/[\n\r\f]+/m","<br />", $text); ?>');
The m modifier will match across newlines, which in this case I think is important.
edit: sorry, didn't realise you actually wanted <br /> elements, not spaces. updated answer accordingly.
edit2: like #LainIwakura, I made a mistake in my regexp, partly due to the previous edit. my new regexp only replaces CR/NL/LF characters, not any whitespace character (\s). note there are a bunch of unicode linebreak characters that i haven't acknowledged... if you need to deal with these, you might want to read up on the regexp syntax for unicode
Edit: Okay after much tripping over myself I believe you want this:
$str = preg_replace('/\n+/', '<br />', $str);
And with that I'm going to bed...too late to be answering questions.
I usually use json_encode() to format string for use in JavaScript, as it does everything that's necessary for making JS-valid value.

Categories