Button to send record via email

Wish to see a specific feature/change in future releases? Feel free to post it here, and if it gets enough "likes", we'd definitely include it in future releases!
Post Reply
toconnell
Veteran Member
Posts: 203
Joined: 2013-04-09 19:29

Button to send record via email

Post by toconnell » 2014-04-11 20:01

Another user on this form requested in the bugs section a button that you can click inside the record that would allow you to email this record to someone.
That seems like it would be rather easy to incorporate under where your Save Changes button area is.. just a thought.. it was a good idea for a program improvement.

Thanks

rmloehmann
Posts: 10
Joined: 2014-03-31 22:28

Re: Button to send record via email

Post by rmloehmann » 2014-05-10 01:42

I would love this feature. I have a reporting program that incorporates this and it makes use of phpmailer to make it happen

toconnell
Veteran Member
Posts: 203
Joined: 2013-04-09 19:29

Re: Button to send record via email

Post by toconnell » 2014-05-23 19:18

What reporting program do you use?

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 209
Joined: 2013-03-21 04:37

Re: Button to send record via email

Post by peebee » 2014-05-27 06:42

Don't know if this will help you but I managed to integrate a relatively straight forward (and unobtrusive) option to email a selected recipient(s) on "Saving" a record with the addition of a check box and a tablename_after_update hook. If the checkbox is checked - an email is sent when the record is Updated. If not - no email sent. Works a treat and very simple to setup.

For purposes of example, I'll use table name of "jobs". Primary key is "id". In this example, all fields mentioned are within the jobs table.

First I add a field for the email address you want to send to. This way, you can change it whenever you want to. Field name "emailto". You can also grab the email address from some other field/table/membership record but for this example, I'll keep it simple.

I add a checkbox (tiny int - field name "emailadvice") with a default value of 0

Then add a simple hook that generates the email after update and then also resets the checkbox value to 0

function jobs_after_update($data, $memberInfo, &$args){

// ******** Send email if checkbox is checked *********
$recipient = $data['emailto'];
$CC = "";
$sendemail=sqlValue("select emailadvice from jobs where id='{$data['selectedID']}'");
if($sendemail!=0){

$resetMail=@mail(
// To
$recipient,

// Subject
"A database record has been updated",

// Content
"Just add whatever content and fields you want to the email.\n" .
"Account No.: {$data['contract']}\n" .
"Name: {$data['name']}\n" .
"Our Job No.: {$data['id']}\n" .
"Current Job Status: {$data['status']}\n" .
"Please login to your account at http://www.yourdomain.com to view all of the details",

// From
"From: no-reply@yourdomain.com"
);
// then update the send email checkbox back to default of 0
if(resetMail){
sql("update jobs set emailadvice=0 where ourref='{$data['selectedID']}'", $abc);
}
}
// ******** End send email if checkbox is checked *******

The checkbox will be set back to default value of 0 (unchecked) after the record is updated and the email is sent. Works well for me and my case. Hope it works for you too.

toconnell
Veteran Member
Posts: 203
Joined: 2013-04-09 19:29

Re: Button to send record via email

Post by toconnell » 2014-06-03 13:55

Thanks PeeBee but I figured it out..

Code: Select all

function compliance_before_update(&$data, $memberInfo, &$args){

          $newdata=sql("select * from compliance where Record_Id='{$data['selectedID']}'");
          while($row=mysql_fetch_row($newdata)){
           foreach($row as $field => $value){
           
            $field_info = mysql_fetch_field($newdata, $field);
    
          $messageData2 .= "$field_info->name: $value \n";
         
          }
           }
           
         $newdata=sql("select * from compliance where Record_Id='{$data['selectedID']}'");
          while($row=mysql_fetch_row($newdata)){
          if($row['Active'])
           $_SESSION['oldisactive']='TRUE';
            else
            $_SESSION['oldisactive']='FALSE';
          	
           }
           
           
           $olddata=$messageData2;
	$_SESSION['olddata']=$olddata;
		
		return TRUE;

	}
and

Code: Select all

function compliance_after_update($data, $memberInfo, &$args){
		
			$olddata=$_SESSION['olddata'];
	
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}

// Capture and log changes to compliance record into the Compliance History Log table
sql("INSERT INTO `Comp_Hist_Log` (`Com_Rec_Id`, `old_data`, `new_data`, `ChangedDate`, `ChangedBy`) VALUES('{$data['Record_Id']}', '{$olddata}', '{$messageData}', '{$data['LastUpdatedby']}', '{$memberInfo['username']}')", $eo);


$fields_to_send = array('Name', 'MailCity', 'MailState', 'Home_County', 'HomePhone', 'CellPhone', 'Email', 'Active','Spare_Driver', 'Not_A_Driver', 'Comments');

$Activenew=$data['Active'];
$Activeold=$_SESSION['oldisactive'];
if($Activeold != $Activenew)

{
$recID=mysql_insert_id();
sql("insert into membership_userrecords set tableName='compliance' , pkValue='#recID', 
memberID=' ".getLoggedMemberID()."', dateAdded=' ".time()."', dateUpdated='".time()."',
groupID= ".getLoggedGroupID().".", $eo);

//Send mail when the active status is changed from FALSE to TRUE or TRUE to FALSE
{
@mail(
// mail recipient
"tinao@domainname.com, user2@domainname.com",
 
// subject
"A Record in the Driver Compliance table of the database was changed (Active Status CHANGE NOTIFICATION) - Driver RECORD NUMBER-{$data['Record_Id']}",
 
// message
      "The above record {$data['Record_Id']} was just modified by:{$memberInfo['username']} The record was updated on and by:{$data['LastUpdatedby']} \n To view the record please go to \n http://bigschoolbus.com/asdata2/compliance_view.php?SelectedID=".$data['selectedID']."  Newly entered data shows as actual table values below:,
	 {$messageData} \n.  The user that changed this record did so from IP Address: {$memberInfo['IP']}  \n\n", 
	  
 
// sender address
"admin@domainname.com"
);
}

return TRUE;
	}
	

rmloehmann
Posts: 10
Joined: 2014-03-31 22:28

Re: Button to send record via email

Post by rmloehmann » 2014-07-17 21:26

I use PHP Report Maker 7.0 for reporting. It seems to work well with App Gini and incorporates phpmailer. I am currently trying to find a way to add a button/link on the detail view in a record that when clicked would take you to the filtered php report maker report for that record and then they can export to email from there. Currently, they have to go to the reports screen, do the search for that record and then export. I like the phpmailer feature because it allows me to design the email with html which creates a nice customer looking document. The customer has no access to the database so the data must be passed in the email and in a nice format. A link to the record is not helpful. I do wish there was a way to do this directly from appgini

facos79
Veteran Member
Posts: 72
Joined: 2014-10-29 12:31

Re: Button to send record via email

Post by facos79 » 2018-06-11 10:11

News on the possibility to send smtp ssl emails with appgini?

Post Reply