如何检查按钮的值并根据phpmailer检查的输入在正文邮件中创建条件?



我创建了一个轮播表单。每张幻灯片只有一个问题。第一张幻灯片上有两个单选按钮。使用 js,如果我单击一个按钮,我有两张幻灯片。如果我点击另一个按钮,我有 10 张幻灯片。然后我想通过在正文邮件中设置条件来通过 phpmailer 发送表单。但它不起作用。 请参阅下面的代码。

有人可以帮助我吗?

谢谢。

<?php
use PHPMailerPHPMailerPHPMailer;
if(isset($_POST['submit'])){
$v1 = $_POST['v1'];
$v2 = $_POST['v2'];
// .....
$msg = '';
if (array_key_exists('userfile', $_FILES)){ 
require './vendor/autoload.php';
// Create a message
$mail = new PHPMailer;
$mail->isHTML(true);
$mail->Host = 'ssl0.ovh.net';
$mail->Port = 465;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->CharSet = 'UTF-8';
$mail->setFrom('mail@example.com',$auditeur);
$mail->addAddress('example@gmail.com', 'Nico');
$mail->Subject = 'My form';
//Attach multiple files one by one
for ($ct = 0; $ct < count($_FILES['userfile']['tmp_name']); $ct++) {
// destination
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name'][$ct]));
// fichier à uploader
$filename = $_FILES['userfile']['name'][$ct];
if(is_uploaded_file($_FILES['userfile']['tmp_name'][$ct])){
// move_uploaded_file déplàce un fichier télécharger vers une destination
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$ct], $uploadfile)) {
$mail->AddEmbeddedImage($uploadfile, "my-attach" . $ct);
} 
else {
$msg .= 'Failed to move file to ' . $uploadfile;
}
}
}
if($v1 == 'value1'){
$mail->Body = '<p> This is the mail 1</p>'
} else {
echo "sd";
$mail->Body .='<p>This is the mail 2</p>'; 
}
if (!$mail->send()) {
$msg .= "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg .= "Thank you ";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- SOME CODE -->
</head>
<body>
<!-- SliDES CAROUSEL -->
<div class="custom-control custom-radio custom-control-inline">
<input href="#" data-target="#carousel-example-2" data-slide-to="1" type="radio" 
class="custom-control-input" id="radio1" name="v1" value="value1">
<label class="custom-control-label" for="radio1">DATA FOR MAIL 1</label>
</div>
<!-- Default inline 2-->
<div class="custom-control custom-radio custom-control-inline">
<input href="#" data-target="#carousel-example-2" data-slide-to="1" type="radio" 
class="custom-control-input" id="radio2" name="v1" value="value2">
<label class="custom-control-label" for="radio2">DATA FOR MAIL 2</label>
</div>
<!-- IF I CLICK ON RADIO 1 I HAVE 2 SLIDES AFTER CONTROLLED WITH JS -->
<!-- IF I CLICK ON RADIO 2 I HAVE 10 SLIDES AFTER CONTROLLED WITH JS -->

</body>

确保输入具有相同的名称和不同的值。 然后,您可以通过检查值来确定单击了哪个按钮。

<?php
echo $_POST['example']; // (Either btn 1 or btn 2 depending on what you picked)
<input type="radio" name="example" value="btn1"> Test 1
<input type="radio" name="example" value="btn2"> Test 2

实际上,我在一个表格中有两个提交。因此,我必须在每个提交按钮上放置不同的值。然后,我必须在提交按钮上而不是在单机按钮上设置条件。

if($_POST['submit'] == 'mail1'{
//send mail 1
else {
send mail 2
}````

最新更新