I am not a programmer and using phprunner to create page to send an email to selected records. I have used some pre-existing code via this link https://phprunner.com/phprunner/docs/email_selected_users.htm and a modification to it on stackoverflow (Thanks [Micheal.M][1]). I need to input the 'from' 'subject' and 'body' via a form. The 'subject' and 'from' parts works fine.
But how can I get the $params["emailBody"] and the $data["FirstName"] both to appear in the 'body' of the email? 'FirstName' field is from a table called Students_ALL.
Can someone please guide me? I have tried for two days and cannot figure it out. Please find the code below: THANK YOU SO MUCH in advance - Mayo
SERVER
if( $params["emailBody"] ||$params["emailSubject"] || $params["emailFrom"] )
{
$emails = array();
while( $data = $button->getNextSelectedRecord() )
{
// Send only if email field not empty
if( $data["Email1"] ) {
// This no longer should be an array of emails
$from = $params["emailFrom"];
$email = $data["Email1"];
$subject = $params["emailSubject"];
$body = $params ["emailBody"];
// Email will be sent for each record
$arr = runner_mail(array('to' => $email, 'subject' => $subject, 'from' => $from, 'htmlbody' => $body));
}
}
$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;
}
}
CLIENT BEFORE
if ( proxy["emailUsers"] === true ) {
params["emailFrom"] = proxy["emailFrom"];
params["emailBody"] = proxy["emailBody"];
params["emailSubject"] = proxy["emailSubject"];
proxy["emailUsers"] = false;
return true;
}
var selBoxes = pageObj.getSelBoxes( pageid ),
args = {
modal: true,
header: "Input from, subject and body",
html: '<div>'
+ '<div>From: <input type="text" id="emailFrom"s style="margin: 5px 0"></div>'
+ '<div>Subject: <input type="text" id="emailSubject"s style="margin: 5px 0"></div>'
+ '<div>Body: <textarea id="emailBody"></textarea></div>'
+ '</div>',
footer: '<a href="#" id="emailUsersSave" class="btn btn-primary">' + Runner.lang.constants.TEXT_SAVE + '</a>'
+ '<a href="#" id="emailUsersCancel" class="btn btn-default">' + Runner.lang.constants.TEXT_CANCEL + '</a>',
afterCreate: function( win ) {
$("#emailUsersSave").on("click", function( e ) {
var context = win.body();
proxy["emailUsers"] = true;
proxy["emailFrom"] = $("#emailFrom", context).val();
proxy["emailBody"] = $("#emailBody", context).val();
proxy["emailSubject"] = $("#emailSubject", context).val();
$('[id="' + ctrl.id + '"]').click();
e.preventDefault();
win.destroy();
});
$("#emailUsersCancel").on("click", function( e ) {
e.preventDefault();
win.destroy();
});
}
};
if ( selBoxes.length == 0 || !confirm('Do you really want to email these records?') ) {
return false;
}
Runner.displayPopup( args );
return false;
CLIENT AFTER
var message = result["txt"] + " !!!";
ctrl.setMessage(message);
[1]: https://stackoverflow.com/users/2432106/michal-m