You'd think that adding a button and having it send an email would be an easy thing to do.... right?
I spent 7 hours yesterday reading hundreds of postings and trying many, many ways.
I have a small email.php code that works when I call it from my web site - so I know that the code and email process works on my server.
FIRST ATTEMPT:
I added a BUTTON on Editor page (Insert Button)... and used the following code:
CLIENT BEFORE:
// Put your code here.
params["txt"] = "Hello";
ctrl.setMessage("Sending request to server...");
// Uncomment the following line to prevent execution of "Server" and "Client After" events.
// return;
SERVER:
// Put your code here.
$result["txt"] = $params["txt"]." world!";
$to = "myaccount@gmail.com";
$subject = "Info Needed";
$message = "You have a message";
$message .= "\n which was approved.";
$message .= "\n Thank you. \n Dave C";
$from = "anotheraccount@somewhere.net";
$headers = "From:" . $from;
runner_mail($to,$subject,$message,$headers);
if (mail($to, $subject,$message,$headers)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed...</p>");
}
CLIENT AFTER:
// Put your code here.
var message = result["txt"];
ctrl.setMessage(message);
-----
RESULT:
The button shows up but it doesn't do anything.
I can NOT find any better instructions, nor an example to use.
---------------------------------------------------------------
SECOND ATTEMPT:
I added PHP Code Snippet.
// Put your code here.
echo "<INPUT class=button type=button value=SEND_EMAIL
onclick='window.location=\"mypage_list.php?editid1=".$_REQUEST["editid1"]."&mail=yes\"'>";
-------
RESULT:
The button is small and has no label (blank).
This solution WORKS and sends an email. Actually it sends TWO emails each time.
----------------------------------------
QUESTIONS:
So, why doesn't the EASIER method work? ie. Adding a button.
And WHERE IN THE DOCUMENTATION does it explain this?
Or where is a working example that I should have followed?
(Like a lot of other people, I really do try to build it all by myself, but the instructions are either lacking, or there aren't links to working examples.)