-5

I want to create an HTML Message to send an email in PHP.

$message = $mess0 . "</br>" . $mess1 . "</br>" . $mess2 . "</br>" .  $mes1 . "</br></br>" . $mes2 . "</br>" . $mes23 . "</br></br>" . $mes3  . "</br></br>" .  $mes4 . "</br>" . $mes5 . "</br>" . $mes6 . "</br>" . $mes7 . "</br>" .  $mes8 . "</br>" .  $mes9 .  "</br></br>" . $mes10 ;

$message =  <html><body><p>$message</p></body></html>;

Here are some variables.

I am getting the following error.

Parse error: syntax error, unexpected '<' in /home/thevowaa/public_html/iphoneapp/webservice/file.php on line 214

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193
  • 4
    It looks like your second line of PHP isn't using quotes to indicate a string, which is creating your parse error. Unless that's a copy/paste error. – Jasper Sep 27 '13 at 17:20

3 Answers3

5

Add HTML tags between double quotes.

$message = "<html><body><p>".$message."</p></body></html>";
Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
Tom
  • 691
  • 4
  • 7
  • please add a little explanation, Tom. otherwise a good answer – Malachi Sep 27 '13 at 17:21
  • it happens. I would like to know about whether or not you can put the Variable inside the quotes or not though – Malachi Sep 27 '13 at 17:24
  • You can add variables inside double quotes and they will be parsed, but not inside single quotes. Inside single quotes $foo will remain litterally $foo – Tom Sep 27 '13 at 18:39
1

Where are the double quotes see below

$message =  "<html><body><p>$message</p></body></html>";
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
  • don't you need to un quote the `$message` variable inside that string? – Malachi Sep 27 '13 at 17:20
  • please post a link or some other evidence to back this up dianuj – Malachi Sep 27 '13 at 17:25
  • inside `"` you can but inside of `'` you can't. you should post this inside of your answer. I still think that this would be bad code practice. – Malachi Sep 27 '13 at 17:28
  • @dianuj - I think you should use one of the following. `$message = "

    " . $message . "

    ";` or `$message = "

    {$message}

    ";`
    – Sina R. Sep 27 '13 at 17:28
  • @Malachi See this fiddle http://phpfiddle.org/main/code/h91-rbs all your answer is in this – M Khalid Junaid Sep 27 '13 at 17:32
  • dianuj, neither his nor your code works on that first site you linked to – Malachi Sep 27 '13 at 17:36
  • just saw the fiddle. it does work in that fiddle. but I still think that it would be bad coding practice to have the variable inside of the quotes – Malachi Sep 27 '13 at 17:38
  • @Malachi you have to run the code there is a button use some common sense :) they clearly placed the button with F9 shortkey too :) – M Khalid Junaid Sep 27 '13 at 17:38
  • 1
    @dianuj +1, you are right but I remember that I got error when I tried this. I don't know maybe my PHP version was different (older) what do you think? – Sina R. Sep 27 '13 at 17:42
  • 2
    @Malachi Variable interpolation is a standard feature of PHP, why not take advantage of it? It's not the best practice to use complex expressions in interpolation (`"Some string {$arr["one"]["two"] + $arr["three"]["four"]}"`) which could get out of hand quickly and make it difficult to follow. But there is nothing wrong with: `"

    Hello $name

    "`.

    – Brandon Buck Sep 27 '13 at 17:42
  • @dianuj, the `phpfiddle` site works, the `writecodeonline` does not – Malachi Sep 27 '13 at 17:44
  • @izuriel Totally agree with you that's what i tried to show Malachi – M Khalid Junaid Sep 27 '13 at 17:44
  • @Malachi writecodeonline works for me this site does not stores your code and neither gives permalink so i can't provide the demo of the code – M Khalid Junaid Sep 27 '13 at 17:47
  • no biggie, add the explanation of the variable interpolation to your answer. far quicker than going back and forth about in comments – Malachi Sep 27 '13 at 17:49
1

There are two possible ways to hold HTML in PHP variable. You can use single quote or double quotes. You also need to put a dot(.) before and after single/double quotes. Your PHP string could be constructed in following two ways:

$message =  '<html><body><p>'.$message.'</p></body></html>';

or like this,

$message =  "<html><body><p>".$message."</p></body></html>";

Also, use of single quotes(') is encouraged in PHP coding because it's doesn't clash with javascript or css double quotes(") when constructing html pages using PHP.

For more information on usage of quotes in PHP, check out this stackoverflow answer

Community
  • 1
  • 1
webblover
  • 1,196
  • 2
  • 12
  • 30