Contact Form: problems when I add another checkbox

2 replies · opened Oct 11, 2017

BbrnEnvatoOct 11, 2017

Hi. I'm working on contact form: when I add the second checkbox, I do not receive the mail.

If I use only a checkbox, everything works well

http://www.brunocover.com/TMP/23S/FERROLI/WEB/07-contact-6-no-recaptcha.html

but if I add the second checkbox, I will not receive any mail

http://www.brunocover.com/TMP/23S/FERROLI/WEB/08-contact-6-no-recaptcha.html

The php file is the same, complete with the second box


<?php

require_once('phpmailer/PHPMailerAutoload.php');

$toemails = array();

$toemails[] = array(
'email' => 'bruno.cover@gmail.com', // Your Email Address
'name' => 'Your Name' // Your Name
);

// Form Processing Messages
$message_success = 'We have successfully received your Message and will get Back to you as soon as possible.';

// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = ''; // Your reCaptcha Secret

$mail = new PHPMailer();

// If you intend you use SMTP, add your SMTP Code after this Line

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if( $_POST['template-contactform-email'] != '' ) {

	$nome = isset( $_POST['template-contactform-nome'] ) ? $_POST['template-contactform-nome'] : '';
	$cognome = isset( $_POST['template-contactform-cognome'] ) ? $_POST['template-contactform-cognome'] : '';
	$piva = isset( $_POST['template-contactform-piva'] ) ? $_POST['template-contactform-piva'] : '';
	$ragionesociale = isset( $_POST['template-contactform-ragionesociale'] ) ? $_POST['template-contactform-ragionesociale'] : '';
	$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
	$phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
	$city = isset( $_POST['template-contactform-city'] ) ? $_POST['template-contactform-city'] : '';
	$cap = isset( $_POST['template-contactform-cap'] ) ? $_POST['template-contactform-cap'] : '';
	$provincia = isset( $_POST['template-contactform-provincia'] ) ? $_POST['template-contactform-provincia'] : '';
	$indirizzopostale = isset( $_POST['template-contactform-indirizzopostale'] ) ? $_POST['template-contactform-indirizzopostale'] : '';
	$codicecat = isset( $_POST['template-contactform-codicecat'] ) ? $_POST['template-contactform-codicecat'] : '';
	$taglia = isset( $_POST['template-contactform-taglia'] ) ? $_POST['template-contactform-taglia'] : '';
	$consenso = isset( $_POST['template-contactform-consenso'] ) ? $_POST['template-contactform-consenso'] : '';
	$mark = isset( $_POST['template-contactform-mark'] ) ? $_POST['template-contactform-mark'] : '';
	
	$subject = isset($subject) ? $subject : 'New Message From Contact Form';

	$botcheck = $_POST['template-contactform-botcheck'];

	if( $botcheck == '' ) {

		$mail-&gt;SetFrom( $email , $name );
		$mail-&gt;AddReplyTo( $email , $name );
		foreach( $toemails as $toemail ) {
			$mail-&gt;AddAddress( $toemail['email'] , $toemail['name'] );
		}
		$mail-&gt;Subject = $subject;

		$nome = isset($nome) ? "Nome: $nome&lt;br&gt;&lt;br&gt;" : '';
		$cognome = isset($cognome) ? "Cognome: $cognome&lt;br&gt;&lt;br&gt;" : '';
		$piva = isset($piva) ? "Partita IVA: $piva&lt;br&gt;&lt;br&gt;" : '';
		$ragionesociale = isset($ragionesociale) ? "Ragione Sociale: $ragionesociale&lt;br&gt;&lt;br&gt;" : '';
		$email = isset($email) ? "Indirizzo Email: $email&lt;br&gt;&lt;br&gt;" : '';
		$phone = isset($phone) ? "Phone: $phone&lt;br&gt;&lt;br&gt;" : '';
		$city = isset($city) ? "Città: $city&lt;br&gt;&lt;br&gt;" : '';
		$cap = isset($cap) ? "CAP: $cap&lt;br&gt;&lt;br&gt;" : '';
		$provincia = isset($provincia) ? "Provincia: $provincia&lt;br&gt;&lt;br&gt;" : '';
		$indirizzopostale = isset($indirizzopostale) ? "Indirizzo Postale: $indirizzopostale&lt;br&gt;&lt;br&gt;" : '';
		$codicecat = isset($codicecat) ? "Codice CAT: $codicecat&lt;br&gt;&lt;br&gt;" : '';
		$taglia = isset($taglia) ? "TAGLIA: $taglia&lt;br&gt;&lt;br&gt;" : '';
		$consenso = isset($consenso) ? "Consenso Privacy e Regolamento: $consenso&lt;br&gt;&lt;br&gt;" : '';
		$mark = isset($mark) ? "Consenso mark: $mark&lt;br&gt;&lt;br&gt;" : '';

		$referrer = $_SERVER['HTTP_REFERER'] ? '&lt;br&gt;&lt;br&gt;&lt;br&gt;This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';

		$body = "$nome $cognome $piva $ragionesociale $email $phone $city $cap $provincia $indirizzopostale $codicecat $taglia $consenso $mark $referrer";

		// Runs only when File Field is present in the Contact Form
		if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
			$mail-&gt;IsHTML(true);
			$mail-&gt;AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
		}

		// Runs only when reCaptcha is present in the Contact Form
		if( isset( $_POST['g-recaptcha-response'] ) ) {
			$recaptcha_response = $_POST['g-recaptcha-response'];
			$response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );

			$g_response = json_decode( $response );

			if ( $g_response-&gt;success !== true ) {
				echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
				die;
			}
		}

		// Uncomment the following Lines of Code if you want to Force reCaptcha Validation

		// if( !isset( $_POST['g-recaptcha-response'] ) ) {
		// 	echo '{ "alert": "error", "message": "Captcha not Submitted! Please Try Again." }';
		// 	die;
		// }

		$mail-&gt;MsgHTML( $body );
		$sendEmail = $mail-&gt;Send();

		if( $sendEmail == true ):
			echo '{ "alert": "success", "message": "' . $message_success . '" }';
		else:
			echo '{ "alert": "error", "message": "Email **could not** be sent due to some Unexpected Error. Please Try Again later.&lt;br /&gt;&lt;br /&gt;**Reason:**&lt;br /&gt;' . $mail-&gt;ErrorInfo . '" }';
		endif;
	} else {
		echo '{ "alert": "error", "message": "Bot **Detected**.! Clean yourself Botster.!" }';
	}
} else {
	echo '{ "alert": "error", "message": "Please **Fill up** all the Fields and Try Again." }';
}

} else {
echo '{ "alert": "error", "message": "An unexpected error occured. Please Try Again later." }';
}

?>


I have allowed to attach compressed folder with the two html files and the php file (in the INCLUDE folder). Please, I have to complete in a short time, can you suggest where I am wrong? Thanks a lot and best regards. Bruno

BbrnEnvatoOct 16, 2017

Please, would you be so kind to answer me? Thanks a lot

BbrnEnvatoOct 16, 2017

I have solved!!! Best regards. Bruno

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard