Im working on a project where I receive a webhook of JSON data that I will then send an email notification based on the JSON. I have all the sorting of the JSON worked out. I know how to send an HTML email via php, but I'm lost on how to build such a large email.
I will need to use some logic to build out parts of the HTML email. But I know something like this will fail because I'm trying to use an If statement inside a variable...
$email = $vendorEmail;
$email_subject = "Order Slip ";
$email_message = '
<table style="width:100%;">
<tbody>
<tr>
<td style="width:33%;">
<h5>Bill To:</h5>
<p style="font-size: 14px;">
<strong>' . $orderInfo->billing_address->first_name . ' ' . $orderInfo->billing_address->last_name . '</strong><br/>
' . if(isset($orderInfo->billing_address->company)){$orderInfo->billing_address->company };. '<br>
' . $orderInfo->billing_address->address1 . '<br/>
' . $orderInfo->billing_address->address2 . '<br/>
</p>
</td>
This is a small section of my overall email. The logic will become much more complex further in the email. An example would be running a for statement to run through all the lines items of a completed order.
Is there a standard way of creating larger more complex HTML emails? Or if not, Does anyone have a suggestion on the smarter way to go about this?