This topic is locked
[SOLVED]

 unset variable

12/5/2018 12:43:46 PM
PHPRunner General questions
P
PaulM author

I'm using a variable to use in a mail. It works ok the first time but when I run it again it doesn't pick up new values, just uses the same one every time.
How do I unset the variable...
I'm using it in the add page, After Record Added Event
I've tried

unset($session['maintenance_details']);

and

$maintenance_details=" ";

admin 12/5/2018

Show us your exact code that sends the email.

P
PaulM author 12/5/2018



Show us your exact code that sends the email.


$ret=runner_mail(array('to' => $email, 'subject' => $subjec, 'body' => $msg, 'from'=>$from));

admin 12/5/2018

The whole code in that event.

P
PaulM author 12/6/2018



The whole code in that event.


$sql = DB::PrepareSQL("select DISTINCT L_email from Maintenance_Quote, Maintenance, Property, Landlord where (MQ_M_id=M_id) and (M_P_id=P_id) and (P_L_id=L_id) and (MQ_id=$value(MQ_id))");

$landlord_email=DBLookup( $sql );

if (!empty($landlord_email))

{

$email=$landlord_email;

}

else

{

$email='Paul@sov.co.uk';

}
//**

//Get the Property Address

//**

$sql = DB::PrepareSQL("select DISTINCT P_name_number from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address1=DBLookup( $sql );

$sql = DB::PrepareSQL("select DISTINCT P_street from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address2=DBLookup( $sql );

$sql = DB::PrepareSQL("select DISTINCT P_area from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address3=DBLookup( $sql );

$sql = DB::PrepareSQL("select DISTINCT P_town from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address4=DBLookup( $sql );

$sql = DB::PrepareSQL("select DISTINCT P_county from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address5=DBLookup( $sql );

$sql = DB::PrepareSQL("select DISTINCT P_postcode from Maintenance_Quote, Maintenance, Property where (MQ_M_id=M_id) and (M_P_id=P_id) and (MQ_id=$value(MQ_id))");

$property_address6=DBLookup( $sql );
//

// Get Lanldord title

//


$sql = DB::PrepareSQL("select DISTINCT L_title from Maintenance_Quote, Maintenance, Property, Landlord where (MQ_M_id=M_id) and (M_P_id=P_id) and (P_L_id=L_id) and (MQ_id=$value(MQ_id))");

$landlord_title=DBLookup( $sql );
//

// Get Lanldord Surname

//


$sql = DB::PrepareSQL("select DISTINCT L_last_name from Maintenance_Quote, Maintenance, Property, Landlord where (MQ_M_id=M_id) and (M_P_id=P_id) and (P_L_id=L_id) and (MQ_id=$value(MQ_id))");

$landlord_surname=DBLookup( $sql );
//

//Lookup Maintenance Started By

//


$sql = DB::PrepareSQL("select DISTINCT M_started_by from Maintenance_Quote, Maintenance where (MQ_M_id=M_id) and (MQ_id=$value(MQ_id))");

$maintenance_started_by=DBLookup( $sql );
//

// Lookup Maintenance_details

//


$sql = DB::PrepareSQL("select DISTINCT M_maintenance_details from Maintenance_Quote, Maintenance where (MQ_M_id=M_id) and (MQ_id=$value(MQ_id))");

$maintenance_details=DBLookup( $sql );
//

// Check that the Landlord has an email address

//


//$email_present= $landlord_email;

//if (strpos($email_present, '@') == false) {

// $landlord_email='paul@sand.co.uk';

//}
//

//From Office Email address

//


$from="paul@hutt.co.uk";
//

//Email Subject

//


$subject="Maintenance Request ";
//*+++++**

//Get the Landlord Threshold Value

//*
+++++**

$sql = DB::PrepareSQL("SELECT L_maintainence_threshold FROM Landlord, Property, Maintenance, Maintenance_Quote WHERE (MQ_M_id=M_id and M_P_id=P_id and P_L_id=L_id and MQ_M_id=$values[MQ_M_id])");

$authval=DBLookup( $sql );
//*+++++**

// if quote is greater than the landlord threshold

//*
+++++**

if ($values[MQ_quote_cost] > $authval)

{

$status="Quote Obtained - Landlord Authorisation Required";
//

//Request Authorisation from the Landlord to Continue

//

$msg.= "A maintenance Request has been received and needs your authorisation to continue: \n\n\n";
$msg.= "This is an automated message from Estate Manager. It is an unmanned mail address, please do not reply \n\n";

$msg.= "A support engineer may contact you if further information is required otherwise you will be notified of any changes made. \n\n";

$msg.= "Please use the code ".$short_code."100".$values[SR_id]." in any correspondance. \n\n";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}
//

// if quote is less than landlord threshold

//
==

else if ($values[MQ_quote_cost] < $authval)

{

$status="Quote Obtained - Assign Work";
//

//Inform the Landlord of the pending Mainenance

//


$msg.= "Dear ".$landlord_title." ".$landlord_surname. "\r\n\n";
$msg.= "A Maintenance Request Has been Submitted for your property :\n\n\n\n";

$msg.= " ".$property_address1." ".$property_address2. "\n";

$msg.= " ".$property_address3. "\n";

$msg.= " ".$property_address4. "\n";

$msg.= " ".$property_address5. "\n";

$msg.= " ".$property_address6. "\n\n\n";
$msg.= "The request is: ".$maintenance_details. " and was submitted by ".$maintenance_started_by."\n\n";
$msg.= "The following is for information only \n\n\n";

$msg.= "This is an automated message from Estate Manager. ";

$msg.= "The ".$maintenance_started_by. " has instigated the following Maintenance on your property \n";

$msg.= $maintenance_details. " \n\n";

$msg.= "The value of ".$values['MQ_quote_cost']." Is below your threshold of ".$authval." and so doesn't need any interaction \n\n";

$msg.="No Action is Required from yourself. \n\n";
$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];

}
else

{

$status='not right checks';

}

admin 12/6/2018

You use .= concatenation operator everytime meaning that you make your message longer and longer.
Instead of

$msg.= "A maintenance Request has been received and needs your authorisation to continue: \n\n\n";



you need to use

$msg= "A maintenance Request has been received and needs your authorisation to continue: \n\n\n";
P
PaulM author 12/6/2018



You use .= concatenation operator everytime meaning that you make your message longer and longer.
Instead of

$msg.= "A maintenance Request has been received and needs your authorisation to continue: \n\n\n";



you need to use

$msg= "A maintenance Request has been received and needs your authorisation to continue: \n\n\n";



Thanks Sergey,
I'll give it a try

P
PaulM author 12/6/2018



Thanks Sergey,
I'll give it a try


I changed it and that part of the $msg did change but the rest of it stays the same and isn't reset. I've tried to change the $msg. to $msg but I then loose the parts before it.

admin 12/6/2018

You need to explain what "the rest of it stays the same and isn't reset" means?
As far as I can see you have multiple code sections that send the email. In each section, the first code statement that works with $msg variable should be changed from $msg.= to $msg=
Just like the example in my previous post.

P
PaulM author 12/7/2018

No matter what the output should be, I get the following except the value which changes correctly and the 'Agent' which also changes. The address should change and the request but it always stays the same.
All the data is fictitious at the moment so is ok to be displayed.
A maintenance Request has been received and needs your authorisation to continue:
5 Holmsworthy Road

Holmsworthy

Sutton

Cornwall

BS24 9UW
The request is: Flakey paint on the door and was submitted by Agent
The following is for information only
This is an automated message from Estate Manager. The Agent has instigated the following Maintenance on your property

Flakey paint on the door
The value of 99 Is below your threshold of 100 and so doesn't need any interaction
No Action is Required from yourself.

F
fpilot 12/30/2018

Sergey, I have also an issue with the attachment thru email, without attachment it works fine.pls see below:
while( $data = $button->getNextSelectedRecord() )

{

$rs = CustomQuery("select * from DailyReport where DRId=".$data["DRId"]);

$dataE = db_fetch_array($rs);

if($dataE["isEmailSent"]!=1){

$ReportDate=$data["ReportDate"];

$emailcc = $data["EmailCC"];

$TS=$data["Total Sales"];

$TC = $data["Total Covers"];

$YTD=$data["YTD Rise"];

$emailID = $data["DRId"];

$CheckList="CheckList/".$data["CheckLists"];

$emailaddress = $data["EmailAddresses"];

$bodymessage="Daily Report Kamloops Popeyes\n--------------\n";//$data["EmailMessage"];

$subjectemail="Daily Report";//$data["subjectemail"];

$imgdn= "https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=86662&image=1&table=forumreplies";;

$imgup= "https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=86662&image=2&table=forumreplies";;

if($YTD>0){

$img=$imgup;

}else{

$img=$imgdn;

}

$body = "";

//$body .= "\n
<b>$date1\n";

//$body .= "
<b>Total Sales </b>= $TS
\nTotal Covers = $TC
\nDifference from previous year = $YTD %

\n\n";//"" . $data['EmailMessage'] . "\n-----------\n\n";

//$body .= "
<font Color=blue>Regards\n\n Raheel Sheikh\n Manager\n-----------\n\n";

$body .= "<font face=Tahoma size=4 color=#FF4500><strong><h2><u>Daily Sales Report Popeyes Kamloops</u></h2></strong></font>
";

$body .= "<font size=4 color=#130CF4><strong>$ReportDate </strong></font>

";

$body .= "<strong><font size=3 color=red>Total Sales</font></strong> = <font size=3 color=black><strong>$$TS</strong></font>
";

$body .= "<strong><font size=3 color=red>Total Covers</font></strong> = <font size=3 color=black><strong>$TC</strong></font>
";

$body .= "<strong><font size=3 color=red>Difference from previous year</font></strong> = <font size=3 color=black><strong>$YTD %</strong><img src=$img></font>
";

$body .= "<strong><font size=2 color=grey>

Regards
Manager On Duty</font></strong>
";

$email = "$emailaddress";

$subject = "$subjectemail";

$cc="$emailcc";

$from="$FromEmail";

$fromName="$FromName";

////////////////////////

$attachments = array();

// Attachments description. The 'path'(a path to the attachment) is required. Others parameters are optional:

//'name' overrides the attachment name, 'encoding' sets a file encoding, 'type' sets a MIME type

$attachments = array(

array('path' => getabspath('CheckLists/greasetrap kamloops1_lxwbsgka.pdf'),

//array('path' => getabspath('files/Photo12.jpg'),

'name' => 'CheckLists.pdf',

'encoding' => 'base64',

'type' => 'application/octet-stream'))

//array('path' => getabspath('files/signature.jpg'))

;

//////////////////////////

$arr = runner_mail(array('to' => $email,'cc' => $emailcc, 'subject' => $subject,

'htmlbody' => $body, 'fromName'=> $fromName, 'from' => $from, 'attachments' => $attachments, 'charset' => 'UTF-8'));
//$arr = runner_mail(array('to' => $email,'cc' => $emailcc, 'subject' => $subject,'htmlbody' => $body, 'fromName'=> $fromName, 'from' => $from, 'attachments' => $attachments, 'charset' => 'UTF-8'));

$result["txt"].= "Emails ($email,$emailcc, $subject)were sent.
";
if( !$arr["mailed"])

{

$errmsg = "Error happened:
";

$errmsg.= $arr["message"];

/$errmsg.= "File: " . $arr["errors"][0]["file"] . "
";

$errmsg.= "Line: " . $arr["errors"][0]["line"] . "
";

$errmsg.= "Description: " . $arr["errors"][0]["description"] . "
";
/

$result["txt"] = $errmsg;

}

else{

CustomQuery("update DailyReport set isEmailSent=1, YTD Rise=$YTD where DRId=".$emailID);

}

}

}

admin 12/30/2018

Telling why email with attachment doesn't work by just looking at your code is not possible.