engage PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andresmint
Forum Newbie
Posts: 5
Joined: Thu Dec 12, 2013 3:03 pm

engage PHP script

Post by andresmint »

I don't quite know how to implement the script below. It is supposed to email the user their scores from an assessment quiz. After taking the quiz several times it never emails/executes the mailto command:

Code: Select all

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

$emailSubject = 'Lean Healthcare Assessment and Gap Analysis Guide';
$webMaster = 'info@leanfoxsolutions.com';
// $emailField = $_POST['email'];
$email = $_POST['sendTo'];

$total1 = intval($_POST['vision']) + intval($_POST['planning']) + intval($_POST['resources']) + intval($_POST['objectives']) + intval($_POST['accountability']);
$total2 = intval($_POST['listening']) + intval($_POST['measures']) + intval($_POST['benchmarking']) + intval($_POST['expectations']) + intval($_POST['flexibility']) + intval($_POST['equity']);
$total3 = intval($_POST['processfocus']) + intval($_POST['processmeasures']) + intval($_POST['efficiency']) + intval($_POST['influence']) + intval($_POST['processinformation']) + intval($_POST['variation']);
$total4 = intval($_POST['safety']) + intval($_POST['training']) + intval($_POST['development']) + intval($_POST['obstacles']) + intval($_POST['staffaccountability']) + intval($_POST['beingvalued']);
$total5 = intval($_POST['information']) + intval($_POST['monitoring']) + intval($_POST['visibility']) + intval($_POST['decisions']) + intval($_POST['challenge']) + intval($_POST['improvement']);

$average1 = round($total1 / 5, 1);
$average2 = round($total2 / 6, 1);
$average3 = round($total3 / 6, 1);
$average4 = round($total4 / 6, 1);
$average5 = round($total5 / 6, 1);

$body = <<<EOD
Dear Lean Cohort:<br>
<br>
Every journey begins with that first step. By completing the Lean Healthcare Assessment and Gap Analysis you now have an understanding where to initially focus your time and resources. Additionally, your results provide you with a baseline to compare with future improvement initiatives (and subsequent assessments).<br>
<br>
If you have other business performance (scorecard) measurements, you should factor those in to determine where the resources of the organization will most likely have the biggest impact.  Your results along with our downloadable Improvement Guide can be used to assist you in prioritizing where to start your journey and how to best communicate to others.<br>
<br>
Best wishes for a successful journey,<br>

<br>
**********************************************************************************************************************<br>
Where can I learn more about Lean and improving the patient experience?<br>
<br>
Visit TheLeanStore.com to find books like: (1) Value Stream Management for Lean Healthcare (2) The New Lean Healthcare Pocket Guide-Tools for the Elimination of Waste in Hospitals, Clinics, and Other Healthcare Facilities and (3) Practical Lean Six Sigma for Hospitals, Clinics, and Physician Group Practices.<br>

<br>
***********************************************************************************************************************<br>
Sensei Tips<br>
1. It is desirable for Section Scores to achieve a score of 3.6 or above. Scores 3.5 or below represent a gap or opportunity for improvement and/or additional investigation or study. Once you have determined which section (Leadership, Patient Focus, Process Management, People Management, Information and Analysis) to address first, focus on the items that scored the lowest within that section.<br>
2. Download our Improvement Guide in PDF format for practical solutions/suggestions to help you move forward.  If that link doesn’t work, you can find the Improvement Guide by typing or pasting this link:<br>
<a href="www.leanfoxsolutions.com/improvement-guide">www.leanfoxsolutions.com/improvement-guide</a><br>
<br>
Your Lean Healthcare Assessment Results by Section<br>
1. Leadership: $average1<br>
2. Patient Focus: average2<br>
3. Process Management: $average3<br>
4. People Management: $average4<br>
5. Information and Analysis: $average5<br>
<br>
************************************************************************************************************************<br>
Section 1: Leadership Overall section score: $average1<br>
Vision: {$_POST['vision']}<br>
Planning: {$_POST['planning']}<br>
Resources: {$_POST['resources']}<br>
Objectives: {$_POST['objectives']}<br>
Accountability: {$_POST['accountability']}<br>
<br>
Section 2: Patient Focus Overall section score: $average2<br>
Listening: {$_POST['listening']}<br>
Measures: {$_POST['measures']}<br>
Benchmarking: {$_POST['benchmarking']}<br>
Expectations: {$_POST['expectations']}<br>
Flexibility: {$_POST['flexibility']}<br>
Equity: {$_POST['equity']}<br>
<br>
Section 3: Process Management  Overall section score: $average3<br>
Process Focus: {$_POST['processfocus']}<br>
Measures: {$_POST['processmeasures']}<br>
Efficiency: {$_POST['efficiency']}<br>
Influence: {$_POST['influence']}<br>
Information: {$_POST['processinformation']}<br>
Variation: {$_POST['variation']}<br>
<br>
Section 4: Staff Management   Overall section score: $average4<br>
Safety: {$_POST['safety']}<br>
Training: {$_POST['training']}<br>
Development: {$_POST['development']}<br>
Obstacles: {$_POST['obstacles']}<br>
Accountability: {$_POST['staffaccountability']}<br>
Being Valued: {$_POST['beingvalued']}<br>
<br>
Section 5: Information & Analysis  Overall section score: $average5<br>
Information: {$_POST['information']}<br>
Monitoring: {$_POST['monitoring']}<br>
Visibility: {$_POST['visibility']}<br>
Decisions: {$_POST['decisions']}<br>
Challenge: {$_POST['challenge']}<br>
Improvement: {$_POST['improvement']}<br>
<br>
EOD;
$headers = "From: $webMaster\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($email, $emailSubject, $body, $headers);

echo ($success ? "Sent" : "Failed");
?>
Do I need an additional phpmailto.ini script in the root folder of my site to get it to work?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: engage PHP script

Post by requinix »

So you don't get "Sent" or "Failed" messages at all? Then the script isn't even executing in the first place.
andresmint
Forum Newbie
Posts: 5
Joined: Thu Dec 12, 2013 3:03 pm

Re: engage PHP script

Post by andresmint »

I do get an onscreen alert that my message was sent but never arrives in inbox. I'm thinking its because the site isnt yet loaded at leanfoxsolutions web server?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: engage PHP script

Post by requinix »

If you get the message then the code is there and it is, in fact, executing. If you get the Success message then the email isn't being completely rejected at the start (like because of configuration problems or sendmail having issues sending it).

Rather than handle sending the email by yourself in your own code, try something like PHPMailer or SwiftMailer. Both of them are much better at sending emails, not just because they construct the message in such a way that they're less likely to be rejected or sent to a spam folder.
andresmint
Forum Newbie
Posts: 5
Joined: Thu Dec 12, 2013 3:03 pm

Re: engage PHP script

Post by andresmint »

Thanks! As a general rule the php file it must always go in the same directory as index.html? The site will likely be a subdomain of the root folder so I wasn't sure if that would be an issue. (http://www.mysite.com/test)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: engage PHP script

Post by requinix »

Not at all: so long as they're somewhere within the document root of the web server (and even there's ways around that) then it doesn't matter where exactly you put them. Just, you know, make sure you have the right URLs and such.
andresmint
Forum Newbie
Posts: 5
Joined: Thu Dec 12, 2013 3:03 pm

Re: engage PHP script

Post by andresmint »

When you mention adjusting URLs are you talking about the referring file to the php? Also not sure if I need any other php file or server side configuration to allow send?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: engage PHP script

Post by requinix »

...Maybe? The URL is what you put in your HTML to point to "files". It's not necessarily the same thing as the path to the file. For example, on a typical Windows web server there might be a file at C:\htdocs\file.php and the URL might be /file.php - making them the same like that is easy, but really the URL could be something completely arbitrary (so long as the web server knows that it corresponds to file.php). Does that answer that?

As for needing other files, also maybe. Probably. That PHP script is the second half of a mailing thing, it being the part that actually sends the mail. The first half is the one that gathers the information to send; often it's a simple HTML form but in your case it might be Javascript (though probably executing off of details entered into a form).
andresmint
Forum Newbie
Posts: 5
Joined: Thu Dec 12, 2013 3:03 pm

Re: engage PHP script

Post by andresmint »

Very helpful...I've traced my .js on the submit button on the html form. The var URL seems to be wrong

function sendRatings(){
if($('#submit-btn').not(':disabled')){
$('#submit-btn').attr('disabled', 'disabled');

var url = "http://www.loremipsum.com/app_mailResults.php";
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: engage PHP script

Post by requinix »

Yep. You'll need to fix that.
Post Reply