DFD DFD - 6 months ago 23
PHP Question

Email PHP Parse error: syntax error, unexpected ';'

I'm trying to set an if statement in my email body but I got this error. This is the part of the body message in my PHP code:

$body = <<<EOD
<strong>Tipo contatto:</strong> $contacttype <br>
$body .= $contacttype == "telefonopref" ? "<strong>Chiamatemi in questo orario:</strong>".$orariotel."<br>"; <!-- line with error -->
$body.= <<<EOD
<strong>Contatto:</strong> $contatto <br>
<strong>Messaggio:</strong> $message <br>

What's wrong? Any suggestion on how I should write it correctly?
Thanks in advance.

Answer Source

The ternary operator works like this:

$something = $condition ? 'this if true' : 'this if false';

You just need to add the : '' at the end of the line (before the semicolon) for your else statement.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download