This topic is locked
[SOLVED]

 automated report

9/16/2010 8:42:08 AM
PHPRunner General questions
J
jasonfrew author

Hi im looking for a way to schedule phprunner report that will run for example, at 1am, and email its results to a user in the same style as running the report manually.

so with the same formatting, same fields, and same colour coding etc.
Is this something that can be done?
Regards
Jason

Sergey Kornilov admin 9/16/2010

Jason,
to run something automatically on timely fashion you need an external scheduler.
Check this article for inspiration:

http://www.asprunner.com/forums/topic/14793-sample-script-to-send-email-on-timely-fashion/

J
jasonfrew author 9/17/2010

Hi thanks for the info
im nearly there however im not an expert with php yet
//send email for each record

$email=$datatmp["EmailField"]; My table does not contain an email field. i would like to hard code this into the script can you show me how please

//EmailField is your actual field name

$msg="This event was expired\r\n";

$msg.="Quote Number: ".$datatmp["Quote_no"]."\r\n";

$msg.="Quote Required Date: ".$datatmp["Quote_req_date"]."\r\n";

$subject="Expired";

runner_mail(array('to' => $email, 'subject' => $subject, 'bo

Sergey Kornilov admin 9/17/2010

$email='youremailaddress@domain.com';

J
jasonfrew author 9/17/2010

Thanks for your help

I have nearly completed this part of my project,
the email script now runs without errors

however it doesnt appear to send email
I have set one of the records in my database to a required date of last month, so it should be sending me details on that record
The Other email functions are working using sendmail
My script now looks like this
<?php

include("include/dbcommon.php");

global $dal;

$dalTableName = $dal->Table("Enquiries");

$rstmp = $dalTableName->Query("DATEDIFF(day, GETDATE(), Quote_req_Date)>0","");

while ($datatmp = db_fetch_array($rstmp))

{

//send email for each record

$email='my.email@mydomain.com';

//EmailField is your actual field name

$msg="This event was expired\r\n";

$msg.="Quote Number: ".$datatmp["Quote_no"]."\r\n";

$msg.="Quote Required Date: ".$datatmp["Quote_req_date"]."\r\n";

$subject="Expired";

runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $message));

}

//FieldName1, FieldName2 and ExpiryDate are your actual field names, TableName is your actual table name
Regards
Jason

Sergey Kornilov admin 9/17/2010

A few things to check:

  • replace my.email@mydomain.com with the actual email address
  • make sure email settings are configured properly on your server i.e. you can send emails using PHPRunner events
  • make sure your script doesn't contain any errors

J
jasonfrew author 9/20/2010



A few things to check:

  • replace my.email@mydomain.com with the actual email address
  • make sure email settings are configured properly on your server i.e. you can send emails using PHPRunner events
  • make sure your script doesn't contain any errors


Hi The my.email@mydomain.com is for example purposes and is set to the correct email address in the code
I have tested the email config using events and have sent several email's. when a record is added and also to remind passwords
i am a beginner with php and wouldnt know where to start to find out if the code was incorrect. this code was taken from the example here

http://www.asprunner...timely-fashion/

J
jasonfrew author 9/20/2010

So ive had a small bit of success.
I have changed the SQl query and am now getting the info im after pulled in the query

i am now receiving an error in from the application.
error is:

Parse error: parse error in C:\wamp\www\repmail.php on line 10
code is now:
<?php

include("include/dbcommon.php");

global $dal;

$dalTableName = $dal->Table("Enquiries");

$rstmp = $dalTableName->Query("Quote_req_Date< Getdate());

while ($datatmp = db_fetch_array($rstmp))

{

//send email for each record

$email='j*.f***@h***l.co.uk';

$msg="This event was expired\r\n";

$msg.="Quote Number: ".$datatmp["Quote_no"]."\r\n";

$msg.="Quote Required Date: ".$datatmp["Quote_req_date"]."\r\n";

$subject="Expired";

runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $message));

}

//FieldName1, FieldName2 and ExpiryDate are your actual field names, TableName is your actual table name
line 10 is $msg="This event was expired\r\n";
Any ideas where i have went wrong
Regards Jason

J
jasonfrew author 9/20/2010

hi again
so i have created the script as follows
<?php

include("include/dbcommon.php");

global $dal;

$dalTableName = $dal->Table("Enquiries");
$rstmp = $dalTableName->Query("Quote_req_Date < Getdate()");
while ($datatmp = db_fetch_array($rstmp))

{
$email='j*.***@h**.co.uk';
$msg='Quote is out of date';
$msg.="Quote Number: ".$datatmp["Quote_no"]."\r\n";
$msg.="Quote Required Date: ".$datatmp["Quote_req_date"]."\r\n";
$subject="Quote out of date";
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $message));

}
i have ran the script through http://www.hcibook.com/meandeviation/php-syntax-check/v5-2/syntax-check.php

to check the syntax. this comes back ok.
however i recieve the following error

Technical information

Error type 8

Error description Undefined variable: message

URL hamallcrm/repmail.php?

Error file C:\wamp\www\repmail.php

Error line 23

SQL query select * from [dbo].[Enquiries] where Quote_req_Date < Getdate()
Any help would be greatly appreciated
Regards

J
jasonfrew author 9/20/2010

Correct Script looks like this
<?php

include("include/dbcommon.php");

global $dal;

$dalTableName = $dal->Table("Enquiries");
$rstmp = $dalTableName->Query("DATEDIFF(day, GETDATE(), Quote_req_date)<0","");
while ($datatmp = db_fetch_array($rstmp))

{
$email='myemail@mydomain.co.uk';
$msg="Quote overdue";
$msg.="Quote Number: ".$datatmp["Quote_no"]."\r\n";
$msg.="Date Quote Required: ".$datatmp["Quote_req_date"]."\r\n";
$subject="Quote Overdue";
runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg));

}
Regards

Jason