Problem with form

2 replies · opened May 10, 2016

Rrec111May 10, 2016

I'm trying to make a page for people to submit what they with to receive from our company as seen here http://www.advantethinktank.com/tahoe2/Build/promotions

When the form is submitted, it always returns the error "please fill all forms" but I have filled all the forms. The php code is as follows.

 'test@test.com', // Your Email Address
				'name' => 'Promotions Page' // 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'] != '' ) {

		$name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
		$title = isset( $_POST['template-contactform-title'] ) ? $_POST['template-contactform-title'] : '';
		$address1 = isset( $_POST['template-contactform-address1'] ) ? $_POST['template-contactform-address1'] : '';
		$address2 = isset( $_POST['template-contactform-address2'] ) ? $_POST['template-contactform-address2'] : '';
		$city = isset( $_POST['template-contactform-city'] ) ? $_POST['template-contactform-city'] : '';
		$state = isset( $_POST['template-contactform-state'] ) ? $_POST['template-contactform-state'] : '';
 		$zip = isset( $_POST['template-contactform-zip'] ) ? $_POST['template-contactform-zip'] : '';
		$howlong = isset( $_POST['template-contactform-howlong'] ) ? $_POST['template-contactform-howlong'] : '';
		$products = isset( $_POST['template-contactform-products'] ) ? $_POST['template-contactform-products'] : '';
		$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';

		$subject = isset($subject) ? $subject : 'New Message From Promotions Form';

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

		if( $botcheck == '' ) {

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

			$name = isset($name) ? "Name: $name

" : '';
			$title = isset($title) ? "Title: $title

" : '';
			$address1 = isset($address1) ? "Address: $address1

" : '';
			$address2 = isset($address2) ? "Apt, Suite, Bldg.: $address2

" : '';
			$city = isset($city) ? "City: $city

" : '';
			$state = isset($state) ? "State: $state

" : '';
			$zip = isset($zip) ? "Zip Code: $zip

" : '';
			$howlong = isset($howlong) ? "How Long I've Been A Tahoe Enthusiast: $howlong

" : '';
			$products = isset($products) ? "Products I'm Interested In: " . ( is_array($products) ? implode( ', ', $products ) : $products ) . "

" : '';
			$message = isset($message) ? "Message: $message

" : '';

			$referrer = $_SERVER['HTTP_REFERER'] ? '

This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';

			$body = "$name $title $address1 $address2 $city $state $zip $howlong $products $message";

			if( isset( $_FILES['template-contactform-file'] ) AND is_array( $_FILES['template-contactform-file'] ) ) {
				$countfiles = count( $_FILES['template-contactform-file'] );
				for( $i=0; $i IsHTML(true);
						$mail->AddAttachment( $_FILES['template-contactform-file']['tmp_name'][$i], $_FILES['template-contactform-file']['name'][$i] );
					}
				}
			}

			// 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->success !== true ) {
					echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
					die;
				}
			}

			$mail->MsgHTML( $body );
			$sendEmail = $mail->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.

**Reason:**
' . $mail->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." }';
}

?>

What am I doing wrong?

Rrec111May 10, 2016

<?php

require_once('phpmailer/PHPMailerAutoload.php');

$toemails = array();

$toemails[] = array(
'email' => 'test@test.com', // Your Email Address
'name' => 'Promotions Page' // 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'] != '' ) {

	$name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
	$title = isset( $_POST['template-contactform-title'] ) ? $_POST['template-contactform-title'] : '';
	$address1 = isset( $_POST['template-contactform-address1'] ) ? $_POST['template-contactform-address1'] : '';
	$address2 = isset( $_POST['template-contactform-address2'] ) ? $_POST['template-contactform-address2'] : '';
	$city = isset( $_POST['template-contactform-city'] ) ? $_POST['template-contactform-city'] : '';
	$state = isset( $_POST['template-contactform-state'] ) ? $_POST['template-contactform-state'] : '';
		$zip = isset( $_POST['template-contactform-zip'] ) ? $_POST['template-contactform-zip'] : '';
	$howlong = isset( $_POST['template-contactform-howlong'] ) ? $_POST['template-contactform-howlong'] : '';
	$products = isset( $_POST['template-contactform-products'] ) ? $_POST['template-contactform-products'] : '';
	$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';

	$subject = isset($subject) ? $subject : 'New Message From Promotions 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;

		$name = isset($name) ? "Name: $name&lt;br&gt;&lt;br&gt;" : '';
		$title = isset($title) ? "Title: $title&lt;br&gt;&lt;br&gt;" : '';
		$address1 = isset($address1) ? "Address: $address1&lt;br&gt;&lt;br&gt;" : '';
		$address2 = isset($address2) ? "Apt, Suite, Bldg.: $address2&lt;br&gt;&lt;br&gt;" : '';
		$city = isset($city) ? "City: $city&lt;br&gt;&lt;br&gt;" : '';
		$state = isset($state) ? "State: $state&lt;br&gt;&lt;br&gt;" : '';
		$zip = isset($zip) ? "Zip Code: $zip&lt;br&gt;&lt;br&gt;" : '';
		$howlong = isset($howlong) ? "How Long I've Been A Tahoe Enthusiast: $howlong&lt;br&gt;&lt;br&gt;" : '';
		$products = isset($products) ? "Products I'm Interested In: " . ( is_array($products) ? implode( ', ', $products ) : $products ) . "&lt;br&gt;&lt;br&gt;" : '';
		$message = isset($message) ? "Message: $message&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 = "$name $title $address1 $address2 $city $state $zip $howlong $products $message";

		if( isset( $_FILES['template-contactform-file'] ) AND is_array( $_FILES['template-contactform-file'] ) ) {
			$countfiles = count( $_FILES['template-contactform-file'] );
			for( $i=0; $i &lt; $countfiles; $i++ ) {
				if ( isset( $_FILES['template-contactform-file']['tmp_name'][$i] ) ) {
					$mail-&gt;IsHTML(true);
					$mail-&gt;AddAttachment( $_FILES['template-contactform-file']['tmp_name'][$i], $_FILES['template-contactform-file']['name'][$i] );
				}
			}
		}

		// 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;
			}
		}

		$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." }';
}

?>

SSemicolon WebSTAFFMay 12, 2016

Hello,

We have just checked out your Website and found out that you are not using any Email Address Input for the Form which is why you are facing this issue. If you are not planning to use an Email Address Input for your Form, you will need to remove the if( $_POST['template-contactform-email'] != '' ) Condition from your include/sendemail.php File.

This will definitely work fine. Let us know if we can help you with anything else or if you find any further issues.

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