Email multiple people after update hook

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Email multiple people after update hook

Post by bruceholt » 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:

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;
	}
	
Thanks in advance. Bruce.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Email multiple people after update hook

Post by a.gneady » 2018-10-11 14:11

Try this:

Code: Select all

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" .
	"Cc: [email protected]\r\n"
);
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Email multiple people after update hook

Post by bruceholt » 2018-10-12 20:21

Hi,

I tried that but unfortunately with that line in it, sales_view.php returns a blank page.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Email multiple people after update hook

Post by a.gneady » 2018-10-18 11:35

Hmm .. is there any error message reported in your server's error_log file?
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Email multiple people after update hook

Post by bruceholt » 2018-10-29 04:58

Thanks all working now but I'm not sure what I did :?

Post Reply