Different Auto-respond Feedbacks Based on Selected Radio Button with PHPMailer

71 Views Asked by At

I am using PHPMailer to collect form data and send and auto response to the users mail. I have 3 different radio buttons to choose from. I need to customize the auto response based on the selected radio button.

<form action="mailer.php" method="POST" name="xform">
<input type="radio" name="summit" id="summit" value="bird" >
<label for="summit">regular</label>
<input type="radio" name="summit" id="summit1" value="duck">
<label for="summit1">vip</label>
<input type="radio" name="summit" id="summit2" value="eagle">
<label for="summit2">vvip</label>
<button name="submitted" type="submit" >Send</button>
</form>

For PHPMAILER
if(isset($_POST['submitted'])){
  $which = $_POST['summit'];
  <!--this picks the selected radio button value -->
}

<!--For Autoresponse -->
if($mail->send()){
 $autoemail->Body = "I need a way to customize this body of the auto respose mail in accordance with the selected radio button, like if $which is an array, how do I customize the auto response in accordance with the selected child";
}

Please note that my PHPMAILER configuration works fine with no issues.

1

There are 1 best solutions below

0
Synchro On BEST ANSWER

Uh, you need to set the body before you send the message!

To pick different message bodies according to your radio button value:

switch($_POST['summit']) {
    case 'bird':
        $mail->Body = "Message body 1";
        break;
    case 'duck':
        $mail->Body = "Message body 2";
        break;
    case 'eagle':
        $mail->Body = "Message body 3";
        break;
}
$mail->send();

You can of course get your message content from any source - from an external file, from a database, from an external HTTP request etc - PHPMailer doesn't care where it's from, so long as you put it into Body.