This topic is locked

Email selected records

11/8/2014 5:59:58 PM
PHPRunner General questions
N
nti author

From tutorial Xlinesoft Help File
Been trying to modify below code without success...
What I am hoping for is (Send the email to email address as listed in table column/field) instead of hard code email address.
Something like:

$emails[] = $data["EmailField"];



$body = "";

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

{

$body .= "OrderID: " . $data['OrderID'] . "\n";

$body .= "Customer: " . $data['CustomerID'] . "\n";

$body .= "Employee: " . $data['EmployeeID'] . "\n-----------\n\n";

}



// send the email

$email = "test@test.com"; // < hard coded email address, requires table field email address

$subject = "Sample subject";

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



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

}
Sergey Kornilov admin 11/8/2014
$email = $data["Email"];
N
nti author 11/9/2014


$email = $data["Email"];



Example works as demonstrated in tutorial, but not with modified

$email = $data["email_pri"];


"email_pri" is my email field.
I am using example script as noted below:



$body = "";

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

{

$body .= "OrderID: " . $data['inv_id'] . "\n"; // works

$body .= "Customer: " . $data['FName'] . "\n"; // works

$body .= "Employee: " . $data['email_pri'] . "\n-----------\n\n"; // works

}



// send the email

$email = $data["email_pri"]; // << does not work

//$email = "email@mydomain.com"; // << works

$subject = "Sample subject";

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



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

}
Sergey Kornilov admin 11/9/2014

You need to assign email inside the loop. $data array has no meaning outside of the loop.

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

{

$body .= "OrderID: " . $data['inv_id'] . "\n"; // works

$body .= "Customer: " . $data['FName'] . "\n"; // works

$body .= "Employee: " . $data['email_pri'] . "\n-----------\n\n"; // works

$email = $data["email_pri"];

}