This topic is locked
[SOLVED]

 Custom Button and Email Help

10/11/2019 2:05:03 PM
PHPRunner General questions
B
bcritchley author

My table has a field called Custodial_Email that contains a valid email address. I am trying to have a custom button at the bottom of the edit page that would allow my staff to send some information on the current record to the email address contained within the Custodial_Email field of the same record. I found the section of the manual that deals with this "Send an email to selected users" and copied the code in the first setup and changed to the fields in red accordingly, but when I build and run it is giving me an error.
Error I receive on Edit Page after build and trying button

Error happened:

File: C:\inetpub\wwwroot\Projects\Requests\output\include\phpfunctions.php

Line: 277

Description: mail(): SMTP server response: 503 5.5.2 Need rcpt command
Server Tab Code of Custom Button
// Place event code here.

// Use "Add Action" button to add code snippets.
// Put your code here.

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

{

if( $data["Custodial_Email"] )

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

}
// send the email

$email = implode(", ", $emails);

$subject = "Sample subject";

$body = "Your email text here";

$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;

}
Client After Tab of button
// Put your code here.

var message = result["txt"];

ctrl.setMessage(message);

Sergey Kornilov admin 10/11/2019

My suggestion is to start with a single hardcoded email address. If you will be getting exactly the same error message that would mean something is wrong with mail server configuration. There is a bunch of possible reasons for this kind of error listed here: https://www.werockyourweb.com/503-valid-rcpt-command-must-precede-data/
You will have to double-check all SMTP settings.

B
bcritchley author 10/12/2019



My suggestion is to start with a single hardcoded email address. If you will be getting exactly the same error message that would mean something is wrong with mail server configuration. There is a bunch of possible reasons for this kind of error listed here: https://www.werockyourweb.com/503-valid-rcpt-command-must-precede-data/
You will have to double-check all SMTP settings.


It appears my SMTP settings were incorrect, I had the wrong port for Gmail. I changed it to 465 and it is now working with a hardcoded To addres, but when I put the variable back in it stops work with no error now.
This line works

$arr = runner_mail(array('to' => 'brent.critchley@greececsd.org', 'subject' => $subject, 'body' => $body));
But this one does not

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

Sergey Kornilov admin 10/12/2019

This means you do not have a correct email or emails in $email variable. Instead of sending the email print the $email variable on the page to see what is in there.

B
bcritchley author 10/23/2019



My table has a field called Custodial_Email that contains a valid email address. I am trying to have a custom button at the bottom of the edit page that would allow my staff to send some information on the current record to the email address contained within the Custodial_Email field of the same record. I found the section of the manual that deals with this "Send an email to selected users" and copied the code in the first setup and changed to the fields in red accordingly, but when I build and run it is giving me an error.
Error I receive on Edit Page after build and trying button

Error happened:

File: C:\inetpub\wwwroot\Projects\Requests\output\include\phpfunctions.php

Line: 277

Description: mail(): SMTP server response: 503 5.5.2 Need rcpt command
Server Tab Code of Custom Button
// Place event code here.

// Use "Add Action" button to add code snippets.
// Put your code here.

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

{

if( $data["Custodial_Email"] )

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

}
// send the email

$email = implode(", ", $emails);

$subject = "Sample subject";

$body = "Your email text here";

$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;

}
Client After Tab of button
// Put your code here.

var message = result["txt"];

ctrl.setMessage(message);


If anyone were able to offer some help I would appreciate it. I am just learning PHP so my abilities are "beginner level" at best. I seem to be getting stuck at the proper syntax to reference my fields from the database properly.
This line works

$arr = runner_mail(array('to' => 'brent.critchley@greececsd.org', 'subject' => $subject, 'body' => $body));
But this one does not

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

B
bcritchley author 10/25/2019

I could not figure out how to get the button to work as I wanted so I ended up changing the on edit event to include the following so that when the field value is changed, that triggers the email.
Still not sure why I could not get the button to work, I'm hoping to revisit as I gain more experience in the application.
if ($values["Custodial_Email"]!=$oldvalues["Custodial_Email"]) {
//** Send email with new data ****
$email=$values['Custodial_Email'];

$from="central.stores@greececsd.org";

$msg.= "Central Stores would like your help with the following.".$values['Custodial_Notes']."\r\n\n";

$subject="Central Stores is requesting your help with the following request".$values['Custodial_Notes']."\r\n\n";
$msg.= "Request Number: ".$values['Request_Number']."\r\n";

$msg.= "Customer: ".$values['Requestor_Name']."\r\n";

$msg.= "Latest Pickup Date: ".$values['Latest_Pickup_Date']."\r\n";

$msg.= "Pickup from: ".$values['Pickup_Location']."\r\n";

$msg.= "Deliver to: ".$values['Destination_Location']."\r\n";

$msg.= "Request: ".$values['Details']."\r\n";
$ret=runner_mail(array('to' => $email, 'bcc' => 'central.stores@greececsd.org', 'subject' => $subject, 'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"];
}