Page 1 of 1

Send email containing data just inserted in the table

Posted: 2017-10-31 14:09
by facos79
Hi everyone, I'm crazy. I can not solve the problem.
I have a table where the assistance intervals are entered. Once you've entered the line, I would like to have it sent to my final customer an email containing the summary of what's included in the table or a link that points to the table's visible page without registration.
How do I do it?
Below the code. What am I doing wrong ?



Code: Select all

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


$EmailI=sqlValue("SELECT `Email` FROM `Clienti` WHERE `id`=".$data['Cliente']);
$dc=sqlValue("SELECT `Durata_ore` FROM `Contratti` WHERE `id`=".$data['Durata_contratto']);

$Clientem=sqlValue("SELECT `Ragione_Sociale` FROM `Clienti` WHERE `id`=".$data['Ragione_Sociale`']);
$Datam=sqlValue("SELECT `Data` FROM `Interventi` WHERE `id`=".$data['Cliente']);
$Descrizione_interventom=sqlValue("SELECT `Descrizione_intervento` FROM `Interventi` WHERE `id`=".$data['Cliente']);
$Durata_interventom=sqlValue("SELECT `Durata_intervento` FROM `Interventi` WHERE `id`=".$data['Cliente']);

$sum=sqlValue("SELECT sum(`Durata_intervento`) FROM `Interventi` WHERE `Cliente`=".$data['Cliente']);
		
$rr=$dc-$sum;
sql("UPDATE `Interventi` SET `Ore_rimanenti`='".$rr."' WHERE `id`=".$data['selectedID'],$eo);



	foreach($data as $field => $value){
		$messageData .= "$field: $value \n";
	}


@mail(
		// mail recipient
		"$EmailI",
		
		// subject
		"Intervento eseguito - Consulente Tecnico Informatico",
		
		// message
		" Ho eseguito un nuovo intervento, puoi visualizzare il riepilogo ".

	
"Cliente: $Clientem \n" .
"Data: $Datam \n" .
"Intervento: $Descrizione_interventom \n " .
"OreContratto: $dc \n" .
"Durata: $Durata_interventom \n" .
"Ore Rimanenti: $Ore_rimanenti \n" ,


		
		// sender address
		"From: [email protected]"


		
	);



		return TRUE;
	}

Re: Send email containing data just inserted in the table

Posted: 2017-11-14 07:57
by Abeer
have you tried to send email from your admin area and made sure that email configurations and sending email is working fine?

Re: Send email containing data just inserted in the table

Posted: 2017-11-26 20:07
by miteshpc
How to test if the sending of email is working fine after setting the new SMTP facility in admin area? A hook on insert sounds the right way but when it doesn't send via the SMTP server defined, then what to do?

Re: Send email containing data just inserted in the table

Posted: 2017-12-01 09:45
by Bertv
For testing your SMTP settings you can use a dummy smtp server like this one: https://github.com/rnwood/smtp4dev
It works great.

Re: Send email containing data just inserted in the table

Posted: 2017-12-07 18:12
by facos79
Vi ringrazio....