This topic is locked
[SOLVED]

 Send E-Mail only if one column is updated

10/16/2019 6:08:50 PM
PHPRunner General questions
M
Melanie authorDevClub member

I have an HTML email that is being sent on a record edit - (after record updated event). The e-mail it sends is very nice and is working well, but I have 2 columns that can be edited there, Employee name and Confirmation number. I need one e-mail to go if the employee name changes and a different one to go if the confirmation number changes.
I have tried some if then statements comparing $value and $oldvalue, but I am not getting it to work correctly (bad syntax) can someone help?

Sergey Kornilov admin 10/17/2019

Something like this:

if ($values["Employee name"]!=$oldvalues["Employee name"]) {

// send your email here

}
M
Melanie authorDevClub member 10/22/2019

So I tried this - and echoed the $values and the $oldvalues to make sure they were different, but the mail does not send - the else happens.
if ($values['emp_name']!=$oldvalues['emp_name'])

{

$email="this@this.com";// your email, please change

$msg="";

$msg.="<html>

<head>

<title>Hotel Cancellation Notice!</title>

</head>

<body>

<table width=\"778\" border=\"1\" cellspacing=\"10\" cellpadding=\"10\" style=\"border:1px dashed #DFF2F6;\">

<tr>

<td>

<h2>Hotel Cancellation Notice</h2>
<p>Your hotel reservation shown below has been cancelled.</p>

<table border=\"0\" width=\"600\" cellspacing=\"10\" cellpadding=\"0\">

<tr>

<td valign=\"top\">Hotel Name</td>

<td valign=\"top\">".$values["hotel_name1"]."</td>

</tr>

<tr>

<td valign=\"top\">Address</td>

<td valign=\"top\">".$values["address"]."</td>

</tr>

<tr>

<td valign=\"top\"> </td>

<td valign=\"top\">".$values["city"]."</td>

</tr>

<tr>

<td valign=\"top\">Check In: </td>

<td valign=\"top\">".$values["checkin"]."</td>

</tr>

<tr>
<td valign=\"top\">Check Out: </td>

<td valign=\"top\">".$values["checkout"]."</td>

</tr>

<tr>

<td valign=\"top\">Confirmation Number: </td>

<td valign=\"top\">".$values["Confirmation_Number"]."</td>

</tr>

<tr>

<td valign=\"top\">Name:</td>

<td valign=\"top\">".$oldvalues["emp_name"]."</td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

";
$subject="Hotel Cancellation";
$from="this@this.com";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $msg, 'from'=>$from));// Note 'htmlbody' instead of 'html'!

if(!$ret["mailed"])

{echo $ret["message"];}

}

else

{

echo "this is the else";
}

M
Melanie authorDevClub member 10/24/2019

so I have tested some more and discovered that if I echo $values["emp_name"] and $oldvalues["emp_name"] they are the same. So that is why I am getting the else statement (and they are both showing the old value). So why is $values not giving me the new one?

lefty 10/25/2019



so I have tested some more and discovered that if I echo $values["emp_name"] and $oldvalues["emp_name"] they are the same. So that is why I am getting the else statement (and they are both showing the old value). So why is $values not giving me the new one?


The only thing I see is this line here which should work but does not need the curly brackets.
echo $ret["message"];
Then try this first . Secondly if you get the email to work and values are correct , add back the html and htmlbody!
if ($values["emp_name"]!=$oldvalues["emp_name"]) [size="2"]{ [/size]
$email="test@emailhere.com";

$from="Your@emailhere.com";

$msg="";

$subject="Hotel Cancellation Notice ";
$msg.= "Old Employee : ".$oldvalues["emp_name"]."\r\n"; // check values of names

$msg.= "New Employee : ".$values["emp_name"]."\r\n"; // check values of names
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}

else**{

}



**

Also: So we all know what version build is this???

M
Melanie authorDevClub member 10/25/2019

The e-mail itself works - if I change the if to be = instead of != the email sends. The problem is that $values is always = $oldvalues so I cannot seem to correctly use an if else as I would like. And I am using 10.1 for this project.

Sergey Kornilov admin 10/25/2019

You should try the latest version. Maybe you are dealing with the bug that was fixed in later versions.

M
Melanie authorDevClub member 10/31/2019

I just tried it in the latest version I am doing this currently:
echo $values["emp_name"];

echo $oldvalues["emp_name"];
The values are the same (they are both the old value).

Sergey Kornilov admin 10/31/2019

I have tested in PHPRunner 10.3 and it prints to different values in AfterEdit evenm.

echo $values["Description"];

echo $oldvalues["Description"];


This, of course, only works if "Description" field was changed on the Edit page.