send html formatted emails to all portal members

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

send html formatted emails to all portal members

Post by fgazza » 2019-11-07 17:15

Hello everyone!
there is a way to send html formatted emails using the utility in the administrative area (the one that allows you to send an email to all members of the portal?).
I tried to paste the html code in the box but it doesn't work!
Is there a solution?
THANKS!
Fabiano

sabukishik
Posts: 2
Joined: 2019-11-10 15:52

Re: send html formatted emails to all portal members

Post by sabukishik » 2019-11-12 19:56

i don't know if there is any method you can do it from admin area, but you can do the following :
  • 1. on your appgini, create a new table with this fields :
    • subject (varchar)
    • message(text)
    let's call the new table "html_emails_sender".
  • 2. on your appgini, generate your app code again (be careful of losing your customization if any).
  • 3. go and edit the file hooks/html_emails_sender.php, scroll down to bottom and add this function :

    Code: Select all

    	function Send_Notification($data) {
    
    		/*selecting users data from users table, supposing field custom1 contain full user name*/
    		$NotificationList = "Select email, custom1 From membership_users" ;
    		$TargetEmails = db_query($NotificationList);
    		
    		/*message filed where you add your html*/
    		$message = makeSafe($data['message']);
    		$subject = makeSafe($data['subject']);
    		
    		while ($list = db_fetch_assoc($TargetEmails)) {;
    			
    			sendmail(array(
    			'to' => $list['email'],
    			'name' => $list['custom1'],
    			'subject' => $subject ,
    			'message' => $message
    			));	
    		
    		}
    	}
  • 4. scroll up to till you find :

    Code: Select all

    function html_emails_sender_after_insert($data, $memberInfo, &$args){
    add below (inside the html_emails_sender_after_insert function) :

    Code: Select all

    Send_Notification($data);
  • 5. now go to user area, add new record to the table html_emails_sender, fill the subject, put your HTML at message field, and save ! all of your users must receive your HTML email now
please note that this is working with SMTP email method, PHP mail() method will not work as per my knowledge.
if you don't want to save every email you send as new record in table html_emails_sender, add

Code: Select all

Send_Notification($data);
to hook

Code: Select all

html_emails_sender_after_update
then just edit the same record every time you want to send an email.

regards
Saleh

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: send html formatted emails to all portal members

Post by fgazza » 2019-11-15 16:01

Thank you very much Saleh!
I will definitely try your solution!
I ask you two more information about your solution ..
1) Can I be sure that each recipient will receive a separate email and will not see the addresses of the other recipients?
2) there is a way to choose, when creating a record, whether to send the mail to all users or users of one or more specific groups? (for example, I image a dropdown list where I choose "all groups" or a specific group (or , even multiple specific groups) taking the list of groups from the relative table.
Thanks!
Fabiano

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: send html formatted emails to all portal members

Post by fgazza » 2019-11-16 21:16

Sorry Saleh but if i have the fields "oggetto" (=field for subject) and "contenuto_messaggio" (field for message) and i set this code:

/*
function html_emails_sender_after_insert($data, $memberInfo, &$args) {

Send_Notification($data);

return TRUE;
}

and at the bottom i set this code:

function Send_Notification($data) {

/*selecting users data from users table, supposing field custom1 contain full user name*/
$NotificationList = "Select email, custom1 From membership_users" ;
$TargetEmails = db_query($NotificationList);

/*message filed where you add your html*/
$message = makeSafe($data['contenuto_messaggio']);
$subject = makeSafe($data['oggetto']);

while ($list = db_fetch_assoc($TargetEmails)) {;

sendmail(array(
'to' => $list['email'],
'name' => $list['custom1'],
'subject' => $subject ,
'message' => $message
));

}
*/

The solution work only if i put not formatted text in the contenuto_messaggio field. If i put for example <b>hello!</b> i have this error saving the form:

Not Acceptable!
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

Hope you will suggest me how to solve it!

Thank you!

Fabiano

Post Reply