gum1982 Posted October 23, 2009 Share Posted October 23, 2009 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 More sharing options...
Bricktop Posted October 23, 2009 Share Posted October 23, 2009 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. Link to comment https://forums.phpfreaks.com/topic/178718-solved-echo-right-results-to-email/#findComment-942744 Share on other sites More sharing options...
gum1982 Posted October 23, 2009 Author Share Posted October 23, 2009 brilliant that worked thankyou. Link to comment https://forums.phpfreaks.com/topic/178718-solved-echo-right-results-to-email/#findComment-942745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.