Jump to content

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 = 'admin@hotmail.com';

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.