php - Can't get radio buttons to work in PHPmailer
Get the solution ↓↓↓First off, I'm not a programming expert by any means. I had a company set PHPmailer for me and they created a simple form and the php code that makes it work. They didn't include radio buttons in the example and I haven't been able to figure out how to make them work. I believe it's something simple but still over my head. The link to the webpage: https://rappahannockfoundation.org/pages/opinion.php
Form code:
<form method="post" action="frmCode_opinion.php">
<p>Which concert did you attend? Click only one.</p>
<p>
<input name="concert" type="radio" value="Face 2 Face">
<label for="Face2Face">Face 2 Face</label>
</p>
<p>
<input type="radio" name="concert" ivalue="Capitol Steps">
<label for="CapitolSteps">Capitol Steps</label></p>
<p>
<input type="radio" name="concert" value="Russian String Orchestra">
<label for="RussianStringOrchestra">Russian String Orchestra</label></p>
<p>
<input type="radio" name="concert" value="Motones vs. Jerseys">
<label for="MotonesJerseys">Motones vs. Jerseys</label></p>
<p>
<input type="radio" name="concert" value="Leahy">
<label for="Leahy">Leahy</label></p>
<p>
<p class="padding_top_10">Would you like to see them for a return performance?</p>
<p><input name="return" type="radio" value="YES"> <label for="return">Yes </label>
<input name="return" type="radio" value="NO"> <label for="return">No </label>
</p>
<p class="padding_top_10">Please rate this program. 1 is poor 5 is excellent.</p>
<p>
<input type="radio" name="rate" value="1"><label for="one">1 </label>
<input type="radio" name="rate" value="2"><label for="two">2 </label>
<input type="radio" name="rate" value="3"><label for="three">3 </label>
<input type="radio" name="rate" value="4"><label for="four">4 </label>
<input type="radio" name="rate" value="5"><label for="five">5 </label>
</p>
<p class="padding_top_10">Please provide comments or suggestions for future performances.
</p>
<textarea style="margin-left:20px;" name="comments" cols="70" rows="5" id="comments"></textarea>
<p><div class="g-recaptcha padding_left_20 marginTop_20" data-sitekey="6LcXnhUUAAAAANRPRnVnY0sZEedUEvsr5lL80Zcj"></div></p>
<p> <input type="submit" name="submit" id="submit" value="Submit"></p>
</form>
PHP code:
<?php
/**
* This example shows how to handle a simple contact form using PHPMailer.
*/
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
$msg = '';
//Don't run this unless we're handling a form submission
if (array_key_exists('email', $_POST)) {
date_default_timezone_set('Etc/UTC');
// the below files are required in order to perform SMTP authentication using the PHPMailer library. If your page/script is under a subdirectory, rather than at the root of the Website directory, then you will need to update the paths here accordingly. For example, if your contact form is located under "/contact/form.php" then you should use a format like: "../phpmailer/src/PHPMailer.php"
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
require 'phpmailer/src/Exception.php';
//Create a new PHPMailer instance, the following lines will remain the same for all sites on your Plesk server
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'secure.emailsrvr.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
//$mail->SMTPAutoTLS = true;
//CAPTCHA CODE
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){ $err = "1";
}
$secretKey = "6LcXnhUUAAAAACRJ2RZ4A2CJmCFdNVxDfV4EbLPx";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
$err = "1";
}
// This will send information from the web server if form doesn't work
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = SMTP::DEBUG_CONNECTION;
$mail->SMTPDebug = 3; //this one is best
// The below parameters must be updated per Website:
// Username (address) and Password to use for SMTP authentication
$mail->Username = '[email protected]';
$mail->Password = 'Cr0ssT0ur!';
//Use the same "Username" fixed address in your own domain as the from address
$mail->setFrom('[email protected]', 'Dave Lipscombe');
//Set the recipient for this email (any email address and name)
$mail->addAddress('[email protected]', 'Dave Lipscombe');
$mail->addBCC('[email protected]', 'Dave Lipscombe');
//Put the submitter's address in a reply-to header
//This will fail if the address provided is invalid,
//in which case we should ignore the whole request
if ($mail->addReplyTo($_POST['email'], $_POST['name'])) {
$mail->Subject = 'Submission from RFA Website';
$mail->isHTML(true);
//Build HTML message body
$emailMessage = "";
$emailMessage .= "<p>Concert: {$_POST['concert']}</p>";
$emailMessage .= "<p>Return performance: {$_POST['return']}</p>";
$emailMessage .= "<p>Program rating: {$_POST['rate']}</p>";
$emailMessage .= "<p>Comments: {$_POST['comments']}</p>";
// store the complete message string in the email body
$mail->Body = $emailMessage;
//set non-html message text for fallback in non-html compatible email software
//Build a simple message body
$mail->AltBody = <<<EOT
Concert: {$_POST['concert']}
Return Performance: {$_POST['return']}
Program rating: {$_POST['rate']}
Program rating: {$_POST['rate']}
Comments: {$_POST['comments']}
EOT;
//Send the message, check for errors
if (!$mail->send()) {
//If you need to debug an error sending, the reason for failing to send will be in $mail->ErrorInfo. Uncomment the below line to enable detailed error reporting, but be warned, this will display detailed error messages to anyone who uses the form while enabled!
print_r($mail->ErrorInfo); //comment this line when not in-use
//but you shouldn't display the details of those errors to users, so only this generic message will display publicly
$msg = 'Sorry, something went wrong. Please try again later.';
} else {
header("Location: thanks.php");
}
} else {
$msg = 'Invalid email address, message ignored.';
}
}
// Below you will find an example form, which includes the basic fields being sent in the email body above.
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: xml parsing error: no root element found
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.