Email multiple people after update hook
Posted: 2018-10-04 09:09
I have a hook after update which emails the customer to notify them that their delivery is on it's way.. I would like to add an email address to that (a permanent email address, not one from the database) so that we have a record of the email that was sent. In other words, a cc (carbon copy) email.
My code is:
Thanks in advance. Bruce.
My code is:
Code: Select all
function sales_after_update($data, $memberInfo, &$args){
ob_start(); ?>
<p>Hello <?php echo sqlValue("select name from customer where id='" . makeSafe($data['customer_name']) . "'"); ?>,</p>
<p>Thank you for your purchase.</p>
<p>Paypal Transaction Number (if applicable): <?php echo $data['paypal_transaction_id']; ?>
<p>Your purchase has been sent via <?php echo sqlValue("select carriers from carriers where id='" . makeSafe($data['carrier']) . "'"); ?> to:</p>
<p><?php echo sqlValue("select address from customer where id='" . makeSafe($data['customer_address']) . "'"); ?><br>
<?php echo sqlValue("select city from customer where id='" . makeSafe($data['customer_address']) . "'"); ?><br>
<?php echo sqlValue("select state from customer where id='" . makeSafe($data['customer_address']) . "'"); ?>, <?php echo sqlValue("select post_code from customer where id='" . makeSafe($data['customer_address']) . "'"); ?><br>
<?php echo sqlValue("select country from customer where id='" . makeSafe($data['customer_address']) . "'"); ?></p>
<p>Tracking number (if applicable): <?php echo $data['tracking_number']; ?></p>
<p>Visit <a href="https://auspost.com.au/mypost/track/#/details/<?php echo $data['tracking_number']; ?>">https://auspost.com.au/mypost/track/#/details/<?php echo $data['tracking_number']; ?></a> to track your delivery.</p>
<?php
$mail_body = ob_get_contents();
ob_end_clean();
$email = sqlValue("select email from customer where id='" . makeSafe($data['customer_name']) . "'");
$emailed = sqlValue("select emailed from sales where sales_number='" . makeSafe($data['customer_name']) . "'");
if($emailed == 'Yes') return true; // return from the function skipping the mail sending part
mail(
$email,
'Kurraglen Industries purchase ' ,
$mail_body,
"From: [email protected]\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=iso-8859-1\r\n"
);
sql("update sales set emailed='Yes' where sales_number='" . makeSafe($data['customer_name']) . "'", $eo);
return TRUE;
}