Jump to content

[SOLVED] Echo right results to email


gum1982

Recommended Posts

hello if got this script below. and everything works fine it take the results from a survey form and tally's them up them echo's the most commonly chosen question.

 

So it echo's the result with an elseif statement but i also need to email the result to the company.

 

How can i email the most commonly chosen answer to the company.

 

How do i take the right echo that has been selected and email it.

 

I'm really stuck here any help would be great.

 

 

<?php

// process.php

$a = 0;

$b = 0;

$c - 0;

 

foreach($_POST as $data)

{

  if($data == 1) {

    $a++;

  } elseif($data == 2) {

    $b++;

  } elseif($data == 3) {

    $c++;

  }

}

?>

 

<?php

 

//how do i take the right echo from here and email it?

 

if($a > $b && $a > $c) {

  echo '<div id="chosen">Mostly As: Congratulations – Your business is in shape.</div>';

} elseif($b > $a && $b > $c) {

  echo '<div id="chosen">Mostly Bs:  Well done – you passed the MOT.</div>';

} else {

  echo '<div id="chosen">Mostly Cs: There are quite a few issues.</div>';

}

 

$survey = Array(1=>'A',2=>'B',3=>'C');

 

 

// Get all $_POST variables

foreach($_POST as $var => $val)

{

${$var} = $val;

}

 

// Set up the email body

$body_body .=  "    First Name-------------| ".$name."\n";

$body_body .=  "    Last Name-------------| ".$last."\n";

$body_body .=  "    Email-------------| ".$email."\n";

 

 

 

 

$to = '[email protected]';

$subject = 'Website Survey Results';

$body = $body_body.$body_footer;

 

mail($to, $subject, $body);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/178718-solved-echo-right-results-to-email/
Share on other sites

Hi gum1982,

 

Amend your echo code to read:

 

if($a > $b && $a > $c) {
  $answer = 'Mostly As: Congratulations – Your business is in shape';
echo '<div id="chosen">'.$answer.'</div>';
} elseif($b > $a && $b > $c) {
  $answer = 'Mostly Bs:  Well done – you passed the MOT.';
echo '<div id="chosen">'.$answer.'</div>';
} else {
  $answer = 'Mostly Cs: There are quite a few issues.;
echo '<div id="chosen">'.$answer.'</div>';
}

 

Then, amend your $body_body code to read:

 

$body_body .=  "    First Name-------------| ".$name."\n";
$body_body .=  "    Last Name-------------| ".$last."\n";
$body_body .=  "    Email-------------| ".$email."\n";
$body_body .=  "    Answer----------------| ".$answer."\n";

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.