This topic is locked
[SOLVED]

Personalize email for selected users

5/29/2021 7:49:04 PM
PHPRunner Tips and Tricks
P
pmaya author

Hi Can someone please point me in the right direction?

I have spent a whole day trying read through many similar queries on the forum and then trying to amend the code, without luck. I am trying to work out what must be a very simple exercise for most of you. I didnt want to give up, but it is now late at night and unfortunately it is now time to swallow my pride and ask for help.

I am using the the code provided here

https://xlinesoft.com/phprunner/docs/email_selected_users.htm but using the second ption - the User enters the subject, email body, "from" email address option.

All I am trying to do is get the first name of each record to auto populate on the email. I have a table called Students_All and the first name field is called FirstName.

Can someone please point me in the right direction? Do I need to lookup these first? I thought that might be the case. But the 'Email' field for each record is found, so why not the First Name also?

Below, I have provided what i now have in the 'server' tab.

Many thanks in advance,

Pedro


$emails = array();
while ( $data = $button->getNextSelectedRecord() )
{
if ( $data["Email1"] )
$emails[] = $data["Email1"];
}

$FirstNames = array();
while ( $data = $button->getNextSelectedRecord() )
{

if ( $data["FirstName"] )
$FirstNames[] = $data["FirstName"];
}

// send the email
$from = $params["emailFrom"];
$email = implode(",", $emails);
$FirstName = implode(",", $FirstNames);
$body = $params["emailBody"];
$subject = $params["emailSubject"];
$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'FirstName' => $FirstName,'body' => $body, 'from' => $from));

$result["txt"] = "Emails were sent.";
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;
}

P
pmaya author 6/7/2021

Hi everyone, After trying for about a hundred hours (I am no programmer) and going through lots of sites on the web, and via trial and error I managed to get it to work. And learn a few things along the way. :-)
I dont know if the code has any security issues, so I am hesitant to post it here as I dont want to get told off. But it works. :-)
Should I post it?
If anyone would like it to modify for their own use, then, let me know and I will send it to you.

Best regards, Pedro