This topic is locked
[SOLVED]

 send an Email with appointments to selected clients

11/29/2018 8:36:07 AM
PHPRunner General questions
I
itmann author

Hi phprunners,
i need some help to resolve this issue:

I have a Table for Client's appointments

Here is the structure:
-AppID

-Client-Name

-Client-Email

-App-Date

-App-Time
Now I need to create a button on the list page to send an Email to the selected clients.

Each client should receive an Email to his own Email address with his own appointment.

Any ideas?
I'd appreciate any help

J
jacques 11/29/2018



Hi phprunners,
i need some help to resolve this issue:

I have a Table for Client's appointments

Here is the structure:
-AppID

-Client-Name

-Client-Email

-App-Date

-App-Time
Now I need to create a button on the list page to send an Email to the selected clients.

Each client should receive an Email to his own Email address with his own appointment.

Any ideas?
I'd appreciate any help


Hi,
Look in the manual for https://xlinesoft.com/phprunner/docs/email_to_selected_users.htm

I
itmann author 11/29/2018

the example in the manual shows how to send a 1 general message to the selected users. it does not show how to include individual content to each user!!

admin 11/29/2018

You can see that first code example at https://xlinesoft.com/phprunner/docs/email_to_selected_users.htm uses $button->getNextSelectedRecord() to loop through selected records.
If you check the manual for this function you can see that you can use $record["FieldName"] to access any field of the next selected record:

https://xlinesoft.com/phprunner/docs/button_getnextselectedrecord.htm
This is how you build your dynamic content for each selected record.

I
itmann author 12/3/2018

Hi,
i followed the instructions and tried this code. it works but the message that the client receives contain the the same data!!

my target is that each client receives an Email with his own appointment.

what did i do wrong?
here is the code
$emails = array();

while( $record = $button->getNextSelectedRecord() )

{

$emails[] = $record["Client-Email"];

$App-Date = $record["App-Date"];

$App-Time = $record["App-Time"];
}
// send the email
$email = implode(", ", $emails);

$subject = "Your Appointment";

$body.="Dear Client </br>";

$body.="Your Appointment Date" .$App-Date."</br>";

$body.="Your Appointment Time" .$App-Time."</br>";
$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $body, 'charset' => 'UTF-8'));
$result["txt"] = "Emails sent.";
// if error happened print a message on the web page
if( !$arr["mailed"] )

{
$errmsg = "Error happened:
";

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

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

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

$result["txt"] = $errmsg;
}
i'd appreciate any help

admin 12/3/2018

You are sending a single email to the list of clients, comma separating email addresses. What you need to do is to send multiple emails, as many emails as the number of selected records. Email sending code needs to stay inside while loop.

while( $record = $button->getNextSelectedRecord() )

{

$email = $record["Client-Email"];

$App-Date = $record["App-Date"];

$App-Time = $record["App-Time"];
// send your email here
}
I
itmann author 12/3/2018

Hi,
Thanks for your message. i have just tried your solution but when i select few clients, only one gets the email. i think there is something missing.

here is my new code for verification:

----------------------------------------------------------------------
while( $record = $button->getNextSelectedRecord() )

{

$email = $record["Client-Email"];

$App-Date = $record["App-Date"];

$App-Time = $record["App-Time"];
}
// send the email
$subject = "Your Appointment";

$body.="Dear Client </br>";

$body.="Your Appointment Date" .$App-Date."</br>";

$body.="Your Appointment Time" .$App-Time."</br>";
$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $body, 'charset' => 'UTF-8'));
$result["txt"] = "Emails sent.";
// if error happened print a message on the web page
if( !$arr["mailed"] )

{
$errmsg = "Error happened:
";

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

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

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

$result["txt"] = $errmsg;
}

admin 12/3/2018

You didn't follow my suggestion. Do you understand what "// send your email here" means?

I
itmann author 12/3/2018

I am afraid not. I am not a professional

HJB 12/3/2018

Simply speaking, admin advised to let the "send e-mail" code of yours to happen INSIDE the "{" and "}" brackets of the WHILE loop, while yours is currently placed OUTSIDE the while loop brackets ...

P.S. "looping" means here, on any loop inside the WHILE code arena the e-mail text shall be used for each new selected e-mail address .., while your placement of code is OUTSIDE the WHILE loop brackets = same mail text to all mail recipients ...

I
itmann author 12/3/2018

Hi,
i got the point and i put the send email inside the While Loop. i selected 3 clients to test and here ist the result:
the good news is: each client has received an email
the bad news is:
the selected client Nr.1 has got an Email containing 1 appointment (his own)

the selected client Nr.2 has got an Email containing 2 appointment (his own + 1 from other client)

the selected client Nr.3 has got an Email containing 3 appointment (his own + 2 from other clients)
something is still wrong here.
here is the currunt code for verfication:
--------------------------------------------------------------------------

while( $record = $button->getNextSelectedRecord() )

{

$email = $record["Client-Email"];

$App-Date = $record["App-Date"];

$App-Time = $record["App-Time"];
// send the email
$subject = "Your Appointment";

$body.="Dear Client </br>";

$body.="Your Appointment Date" .$App-Date."</br>";

$body.="Your Appointment Time" .$App-Time."</br>";
$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'htmlbody' => $body, 'charset' => 'UTF-8'));
}
$result["txt"] = "Emails sent.";
// if error happened print a message on the web page
if( !$arr["mailed"] )

{
$errmsg = "Error happened:
";

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

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

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

$result["txt"] = $errmsg;
}

-----------------------------------------------------------------------------
i am getting crazy. please help

HJB 12/3/2018

Well, rather than aiming to somehow destroy your approach, my understanding on appointment date and time

allocation to certain clients is totally different, say, more practical from the work flow rather than to

run "... coders are dying harder ..." oriented approach solutions. Say, if it would be e.g. me to

act as the "most clever and as well most lazy appointer" I would may want to let the e-mail immediately go out

after I had been placing the appointment within in the page ..., so, for inspiration purposes only, please

check whether such "after adding the appointment into the system" where mail would be sent out automatically,

could/would a workaround for you.
P.S. On "EDIT" = if the date and time needs to get changed for some reasons, the code below needs to be as

well placed within "After Edit Event" too, to get the client informed e.g. about the new date and time.
https://xlinesoft.com/phprunner/docs/runner_mail_function.htm
Send email with new record data. Use this code in the After Add event.





$from = "myemail@test.com";
$to = "myclient@test.com";
$msg = "The new record was added: ";
$subject="New record";

$msg.= "Name: ".$values["name"]."\r\n";
$msg.= "Email: ".$values["email"]."\r\n";
$msg.= "Age: ".$values["age"]."\r\n";

$ret=runner_mail(array('to' => $email, 'subject' => $subject, 'body' => $msg, 'from'=>$from));
if(!$ret["mailed"]){
echo $ret["message"];
}
I
itmann author 12/3/2018

Thanks for your help but this solution does not meet my needs.
I have to send about 50 emails a day with the appointments. That's why I need the button on the list page to do this batch job.

I
itmann author 12/3/2018

Hey guys
Is there a solution for this situation or is it a dead end?

admin 12/3/2018

For each new email you need to reset the $body variable, you currently just keep adding it. You need to do that in the begging of your loop code.

$body.= "...";



The code above adds something to existing $body variable

$body="...";



The code above assigns a new value to the $body variable

I
itmann author 12/4/2018

now it works.

Thank you very very much. you are my hero