Start New Discussion within our Web Development Community

Hi guys, sorry if this has been posted before but I am trying to add a color style to my php mail

Here is a snipper of the code that generates an email, it all works fine. The . $efreeformcompanyname . being a value that may or may not be enetered into a field i have.

        $body .= "Company name - " . $exfreeformcompanyname . "\n";
        $body .= "Address - " . $exfreeformaddress . "\n";
        $body .= "Phone number - " . $exfreeformphone . "\n";

Whats I want is for the . $exfreeformcompanyname . bit to be coloured yellow (background colour) if it has a value and as such appears in the sent email.

I have tried a simple span style but a problem occurs with the "" thats already exists in each line.

Any help would be greatly appreciated.


Have you escaped the double quotes:

if($exfreeformaddress == '') {
    $spanStyle = 'background-color: yellow;';
} else {
    $spanStyle = 'background-color: white;';

$body .= "<span style=\"$spanStyle\">Address - " . $exfreeformaddress . "</span>\n";
This article has been dead for over six months. Start a new discussion instead.