blue_ette
blue_ette

Reputation: 1

If condition in mail body phpmailer

I am using Phpmailer and I am currently emailing the data from my database. However, I need to have a color coding depending on the chosen condition. For example, if the remarks is proceed, the data cell should be in green color and red if hold. Im not really sure how to apply if loop inside an echo. Please help

while ($rowwaf = mysqli_fetch_assoc($queryres)){
$mailbody = "
	Good Day!<br><br>
	Please see details below<br><br>
	<strong>Details:</strong><br><br>
	<table class=\"table\" cellpadding=\"5\" rules=\"all\" frame=\"box\" border=\"1\">
			
			<tr><td class=\"data\"><strong>REQUEST DATE:</strong></td><td>".$rowwaf["req_date"]."</td></tr>
			<tr><td class=\"data\"><strong>ISSUE ENCOUNTERED:</strong></td><td>".$rowwaf["issue"]."</td></tr>	
			<tr><td class=\"data\"><strong>URGENCY:</strong> </td><td>".$rowwaf["urgency"]."</td></tr>
			<tr><td class=\"data\"><strong>REQUESTOR:</strong></td><td>".$rowwaf["requestor"]."</td></tr>
    <tr><td class=\"data\"><strong>REMARKS:</strong></td>
    
    -- if condition sample--
    if {
    $rowwaf["remarks"] == proceed
    <td style="color: green">".$rowwaf["remarks"]."</td></tr>
    }
    else {
    $rowwaf["remarks"] == hold
    <td style="color: red">".$rowwaf["remarks"]."</td></tr>
    }
	";	
		

Upvotes: 0

Views: 365

Answers (1)

Simondebn
Simondebn

Reputation: 23

You could just set a variable for your color(also the code you provided won't work):

<?php
if ($rowwaf['remarks'] === 'proceed') {
   $color = 'green';
} elseif ($rowwaf['remarks'] === 'hold') {
   $color = 'red';
}
?>

Then use the $color variable in your html

I'd also recommend to use heredoc syntax to create your body and use php variables to do something like :

$mailbody = <<<EOF
<td style="color: {$color}">{$rowwaf['remarks']}</td>
EOF;

Upvotes: 1

Related Questions