This topic is locked

Add a BUTTON to SEND EMAIL

11/6/2011 2:24:33 PM
PHPRunner General questions
bbarker author

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.)

Sergey Kornilov admin 11/6/2011

As a first step - take a look at documentation to find what runner_mail() function is and what parameters it expects:

http://xlinesoft.com/phprunner/docs/runner_mail_function.htm
It comes with working examples as well.
My bet is that there is an error in the following line:

runner_mail($to,$subject,$message,$headers);


There is no point in blaming documentation if you are not using it.

C
cgphp 11/6/2011

Documentation is good and examples are very useful:
SERVER

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

$arr = runner_mail(array('to' => $to, 'subject' => $subject, 'body' => $message, 'from' => $from));
if (!$arr["mailed"])

{

$result['msg'] = $arr["errors"][0]["description"];

}

else

{

$result['msg'] = "Message sent";

}


CLIENT AFTER

ctrl.setMessage(result["msg"]);
bbarker author 11/7/2011

Ha ha.. Sergey I'm NOT bashing the documentation... I did find it and tried to use it... But there were a couple of things that I "implied" from it and apparently that kept me from finding the right solution. Let me dig up some examples that "steered" my judgement (mostly from the Forum) and I'll post those in a later note.
By the way, recognize that 1) I'm a guy.... and 2) I would rather run out of gas than stop and ask for directions!. Ha! So, I obviously spent too much time yesterday working on this and I should have posted a note much sooner, but I figured that it wouldn't get a response during the weekend. So I made multiple errors in judgement.
I do think that there are some tweaks that could be made to the documentation... in fact, there are ALWAYS tweaks that could be made... I used to write computing documentation and I know that people think differently and sometimes you need to say the same thing THREE different ways in order for them to understand it. Enough--- I'll try to make my next post useful to you.
One thing that I DID get out of the Forum was a way to test the PHP email code BEFORE trying to run it inside of PHP Runner. That was a HUGE benefit for me... because once I knew that the code worked, then I tried to stick only with what I knew worked... and that's why I didn't try any of the documented examples... Human nature is to stick with something that works. Right? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=62096&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />
One other thought for you... it took quite a while for me to realize that there was a

runner_email ($to,$subject,$message,$headers);



that I needed to use instead of

mail($to,$subject,$message,$headers);



that I used for the first couple of hours.
That might be something to consider "bumping up" on the doc page.
Thanks for the "hints" Sergey and Cristian.