Contact Form just loads...and nothing happens

11 replies · opened Aug 8, 2019

AAnnaRosaSullivanAug 8, 2019

Hi,

I am using the Basic Structure to construct my contact Form but once I try and send the email nothing happens..it just loads..
Do you know what I am doing wrong?

CONTACT.HTML:

	<!-- Content
	============================================= -->
	<section id="content">

		<div class="content-wrap">

			<div class="container clearfix">

				<!-- Postcontent
				============================================= -->
				<div class="postcontent nobottommargin">

					<h3>Send us an Email</h3>

					<div class="form-widget">

						<div class="form-result"></div>

						<div class="form-widget">
<div class="form-result"></div>

<form class="row" id="template-contactform" action="include/form.php" method="post">

	<div class="form-process"></div>

	<div class="col-md-6 form-group">
		<label for="template-contactform-name">Name <small>*</small></label>
		<input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="form-control required" />
	</div>

	<div class="col-md-6 form-group">
		<label for="template-contactform-email">Email <small>*</small></label>
		<input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email form-control" />
	</div>

	<div class="w-100"></div>

	<div class="col-12 form-group">
		<label for="template-contactform-message">Message <small>*</small></label>
		<textarea class="required form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30"></textarea>
	</div>

	<div class="col-12 hidden">
		<input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="form-control" />
	</div>

	<div class="col-12">
		<button class="button button-3d nomargin" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit">Send Message</button>
	</div>

	<!-- Form Settings -->

	<input type="hidden" name="prefix" value="template-contactform-">
	<input type="hidden" name="subject" value="Message from Contact Form">

</form>

</div>
</div>
</div><!-- .postcontent end -->


FORM.PHP:

<?php

/*-------------------------------------------------

Form Processor Plugin
by SemiColonWeb

---------------------------------------------------*/

/-------------------------------------------------
PHPMailer Initialization Files
---------------------------------------------------
/

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

/-------------------------------------------------
Receiver's Email
---------------------------------------------------
/

$toemails[] = array(
'email' => 'seadrec@aol.com', // Your Email Address
'name' => 'Lobnitz Marine Holdings' // Your Name
);

/-------------------------------------------------
Sender's Email
---------------------------------------------------
/

$fromemail = array(
'email' => 'seadrec@aol.com', // Company's Email Address (preferably currently used Domain Name)
'name' => 'Lobnitz Marine Holdings' // Company Name
);

/-------------------------------------------------
reCaptcha
---------------------------------------------------
/

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

/-------------------------------------------------
PHPMailer Initialization
---------------------------------------------------
/

$mail = new PHPMailer();

/* Add your SMTP Codes after this Line */

// End of SMTP

/-------------------------------------------------
Form Messages
---------------------------------------------------
/

$message = array(
'success' => 'We have successfully received your Message and will get Back to you as soon as possible.',
'error' => 'Email could not be sent due to some Unexpected Error. Please Try Again later.',
'error_bot' => 'Bot Detected! Form could not be processed! Please Try Again!',
'error_unexpected' => 'An unexpected error occured. Please Try Again later.',
'recaptcha_invalid' => 'Captcha not Validated! Please Try Again!',
'recaptcha_error' => 'Captcha not Submitted! Please Try Again.'
);

/-------------------------------------------------
Form Processor
---------------------------------------------------
/

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {

$prefix		= !empty( $_POST['prefix'] ) ? $_POST['prefix'] : '';
$submits	= $_POST;
$botpassed	= false;

$message_form					= !empty( $submits['message'] ) ? $submits['message'] : array();
$message['success']				= !empty( $message_form['success'] ) ? $message_form['success'] : $message['success'];
$message['error']				= !empty( $message_form['error'] ) ? $message_form['error'] : $message['error'];
$message['error_bot']			= !empty( $message_form['error_bot'] ) ? $message_form['error_bot'] : $message['error_bot'];
$message['error_unexpected']	= !empty( $message_form['error_unexpected'] ) ? $message_form['error_unexpected'] : $message['error_unexpected'];
$message['recaptcha_invalid']	= !empty( $message_form['recaptcha_invalid'] ) ? $message_form['recaptcha_invalid'] : $message['recaptcha_invalid'];
$message['recaptcha_error']		= !empty( $message_form['recaptcha_error'] ) ? $message_form['recaptcha_error'] : $message['recaptcha_error'];

/*-------------------------------------------------
	Bot Protection
---------------------------------------------------*/

if( isset( $submits[ $prefix . 'botcheck' ] ) ) {
	$botpassed = true;
}

if( !empty( $submits[ $prefix . 'botcheck' ] ) ) {
	$botpassed = false;
}

if( $botpassed == false ) {
	echo '{ "alert": "error", "message": "' . $message['error_bot'] . '" }';
	exit;
}

/*-------------------------------------------------
	reCaptcha
---------------------------------------------------*/

if( isset( $submits['g-recaptcha-response'] ) ) {

	$recaptcha_data = array(
		'secret' =&gt; $recaptcha_secret,
		'response' =&gt; $submits['g-recaptcha-response']
	);

	$recap_verify = curl_init();
	curl_setopt( $recap_verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify" );
	curl_setopt( $recap_verify, CURLOPT_POST, true );
	curl_setopt( $recap_verify, CURLOPT_POSTFIELDS, http_build_query( $recaptcha_data ) );
	curl_setopt( $recap_verify, CURLOPT_SSL_VERIFYPEER, false );
	curl_setopt( $recap_verify, CURLOPT_RETURNTRANSFER, true );
	$recap_response = curl_exec( $recap_verify );

	$g_response = json_decode( $recap_response );

	if ( $g_response-&gt;success !== true ) {
		echo '{ "alert": "error", "message": "' . $message['recaptcha_invalid'] . '" }';
		exit;
	}
}

$template	= !empty( $submits['template'] ) ? $submits['template'] : 'html';
$html_title	= !empty( $submits['html_title'] ) ? $submits['html_title'] : 'Form Response';
$forcerecap	= ( !empty( $submits['force_recaptcha'] ) && $submits['force_recaptcha'] != 'false' ) ? true : false;
$replyto	= !empty( $submits['replyto'] ) ? explode( ',', $submits['replyto'] ) : false;

if( $forcerecap ) {
	if( !isset( $submits['g-recaptcha-response'] ) ) {
		echo '{ "alert": "error", "message": "' . $message['recaptcha_error'] . '" }';
		exit;
	}
}

/*-------------------------------------------------
	Auto-Responders
---------------------------------------------------*/

$autores	= ( !empty( $submits['autoresponder'] ) && $submits['autoresponder'] != 'false' ) ? true : false;
$ar_subject	= !empty( $submits['ar_subject'] ) ? $submits['ar_subject'] : 'Thanks for your Email';
$ar_title	= !empty( $submits['ar_title'] ) ? $submits['ar_title'] : 'Its so good to hear from You!';
$ar_message	= !empty( $submits['ar_message'] ) ? $submits['ar_message'] : 'Autoresponder Message';

preg_match_all('#\{(.*?)\}#', $ar_message, $ar_matches);
if( !empty( $ar_matches[1] ) ) {
	foreach( $ar_matches[1] as $ar_key =&gt; $ar_value ) {
		$ar_message = str_replace( '{' . $ar_value . '}' , $submits[ $ar_value ], $ar_message );
	}
}

$ar_footer	= !empty( $submits['ar_footer'] ) ? $submits['ar_footer'] : 'Copyrights &copy; ' . date('Y') . ' **SemiColonWeb**. All Rights Reserved.';

$mail-&gt;Subject = !empty( $submits['subject'] ) ? $submits['subject'] : 'Form Response from your Website';
$mail-&gt;SetFrom( $fromemail['email'] , $fromemail['name'] );

if( !empty( $replyto ) ) {
	if( count( $replyto ) &gt; 1 ) {
		$replyto_e = $submits[ $replyto[0] ];
		$replyto_n = $submits[ $replyto[1] ];
		$mail-&gt;AddReplyTo( $replyto_e , $replyto_n );
	} elseif( count( $replyto ) == 1 ) {
		$replyto_e = $submits[ $replyto[0] ];
		$mail-&gt;AddReplyTo( $replyto_e );
	}
}

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

$unsets = array( 'prefix', 'subject', 'replyto', 'template', 'html_title', 'message', 'autoresponder', 'ar_subject', 'ar_title', 'ar_message', 'ar_footer', $prefix . 'botcheck', 'g-recaptcha-response', 'force_recaptcha', $prefix . 'submit' );

foreach( $unsets as $unset ) {
	unset( $submits[ $unset ] );
}

$fields = array();

foreach( $submits as $name =&gt; $value ) {

	if( empty( $value ) ) continue;

	$name = str_replace( $prefix , '', $name );
	$name = ucwords( str_replace( '-', ' ', $name ) );

	if( is_array( $value ) ) {
		$value = implode( ', ', $value );
	}

	$fields[$name] = $value;

}

$files = $_FILES;

foreach( $files as $file =&gt; $filevalue ) {

	if( is_array( $filevalue['name'] ) ) {

		$filecount = count( $filevalue['name'] );

		for( $f = 0; $f &lt; $filecount; $f++ ) {
			if ( isset( $_FILES[ $file ] ) && $_FILES[ $file ]['error'][ $f ] == UPLOAD_ERR_OK ) {
				$mail-&gt;IsHTML(true);
				$mail-&gt;AddAttachment( $_FILES[ $file ]['tmp_name'][ $f ], $_FILES[ $file ]['name'][ $f ] );
			}
		}

	} else {

		if ( isset( $_FILES[ $file ] ) && $_FILES[ $file ]['error'] == UPLOAD_ERR_OK ) {
			$mail-&gt;IsHTML(true);
			$mail-&gt;AddAttachment( $_FILES[ $file ]['tmp_name'], $_FILES[ $file ]['name'] );
		}

	}

}

$response = array();

foreach( $fields as $fieldname =&gt; $fieldvalue ) {
	if( $template == 'text' ) {
		$response[] = $fieldname . ': ' . $fieldvalue;
	} else {
		$fieldname = '&lt;tr&gt;
							&lt;td class="hero-subheader__title" style="font-size: 16px; line-height: 24px; font-weight: bold; padding: 0 0 5px 0;" align="left"&gt;' . $fieldname . '&lt;/td&gt;
						&lt;/tr&gt;';
		$fieldvalue = '&lt;tr&gt;
							&lt;td class="hero-subheader__content" style="font-size: 16px; line-height: 24px; color: #777777; padding: 0 15px 30px 0;" align="left"&gt;' . $fieldvalue . '&lt;/td&gt;
						&lt;/tr&gt;';
		$response[] = $fieldname . $fieldvalue;
	}
}

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

$html_before = '&lt;table class="full-width-container" border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" bgcolor="#eeeeee" style="width: 100%; height: 100%; padding: 50px 0 50px 0;"&gt;
			&lt;tr&gt;
				&lt;td align="center" valign="top"&gt;
					&lt;!-- / 700px container --&gt;
					&lt;table class="container" border="0" cellpadding="0" cellspacing="0" width="84%" bgcolor="#ffffff" style="width: 84%;"&gt;
						&lt;tr&gt;
							&lt;td align="center" valign="top"&gt;
								';

$html_after = '&lt;!-- /// Footer --&gt;
							&lt;/td&gt;
						&lt;/tr&gt;
					&lt;/table&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
		&lt;/table&gt;';

if( $template == 'text' ) {
	$body = implode( "&lt;br&gt;", $response ) . $referrer;
} else {
	$html = $html_before . '&lt;!-- / Header --&gt;
								&lt;table class="container header" border="0" cellpadding="0" cellspacing="0" width="84%" style="width: 84%;"&gt;
									&lt;tr&gt;
										&lt;td style="padding: 30px 0 30px 0; border-bottom: solid 1px #eeeeee; font-size: 30px; font-weight: bold; text-decoration: none; color: #000000;" align="left"&gt;
											' . $html_title . '
										&lt;/td&gt;
									&lt;/tr&gt;
								&lt;/table&gt;
								&lt;!-- /// Header --&gt;

								&lt;!-- / Hero subheader --&gt;
								&lt;table class="container hero-subheader" border="0" cellpadding="0" cellspacing="0" width="84%" style="width: 84%; padding: 60px 0 30px 0;""&gt;
									' . implode( '', $response ) . '
								&lt;/table&gt;

								&lt;!-- / Footer --&gt;
								&lt;table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center"&gt;
									&lt;tr&gt;
										&lt;td align="center"&gt;
											&lt;table class="container" border="0" cellpadding="0" cellspacing="0" width="84%" align="center" style="border-top: 1px solid #eeeeee; width: 84%;"&gt;
												&lt;tr&gt;
													&lt;td style="color: #d5d5d5; text-align: center; font-size: 12px; padding: 30px 0 30px 0; line-height: 22px;"&gt;' . strip_tags( $referrer ) . '&lt;/td&gt;
												&lt;/tr&gt;
											&lt;/table&gt;
										&lt;/td&gt;
									&lt;/tr&gt;
								&lt;/table&gt;
								' . $html_after;

	$body = $html;
}

if( $autores && !empty( $replyto_e ) ) {
	$autoresponder = new PHPMailer();

	/* Add your Auto-Responder SMTP Codes after this Line */

	// End of Auto-Responder SMTP

	$autoresponder-&gt;SetFrom( $fromemail['email'] , $fromemail['name'] );
	if( !empty( $replyto_n ) ) {
		$autoresponder-&gt;AddAddress( $replyto_e , $replyto_n );
	} else {
		$autoresponder-&gt;AddAddress( $replyto_e );
	}
	$autoresponder-&gt;Subject = $ar_subject;

	$ar_body = $html_before . '&lt;!-- / Header --&gt;
				&lt;table class="container header" border="0" cellpadding="0" cellspacing="0" width="84%" style="width: 84%;"&gt;
					&lt;tr&gt;
						&lt;td style="padding: 30px 0 30px 0; border-bottom: solid 1px #eeeeee; font-size: 30px; font-weight: bold; text-decoration: none; color: #000000;" align="left"&gt;
							' . $ar_title . '
						&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/table&gt;
				&lt;!-- /// Header --&gt;

				&lt;!-- / Hero subheader --&gt;
				&lt;table class="container hero-subheader" border="0" cellpadding="0" cellspacing="0" width="84%" style="width: 84%; padding: 60px 0 30px 0;""&gt;
					&lt;tr&gt;
						&lt;td class="hero-subheader__content" style="font-size: 16px; line-height: 26px; color: #777777; padding: 0 15px 30px 0;" align="left"&gt;' . $ar_message . '&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/table&gt;

				&lt;!-- / Footer --&gt;
				&lt;table class="container" border="0" cellpadding="0" cellspacing="0" width="100%" align="center"&gt;
					&lt;tr&gt;
						&lt;td align="center"&gt;
							&lt;table class="container" border="0" cellpadding="0" cellspacing="0" width="84%" align="center" style="border-top: 1px solid #eeeeee; width: 84%;"&gt;
								&lt;tr&gt;
									&lt;td style="color: #d5d5d5; text-align: center; font-size: 12px; padding: 30px 0 30px 0; line-height: 22px;"&gt;' . $ar_footer . '&lt;/td&gt;
								&lt;/tr&gt;
							&lt;/table&gt;
						&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/table&gt;
				' . $html_after;

	$autoresponder-&gt;MsgHTML( $ar_body );
}

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

if( $sendEmail == true ):

	if( $autores && !empty( $replyto_e ) ) {
		$send_arEmail = $autoresponder-&gt;Send();
	}

	echo '{ "alert": "success", "message": "' . $message['success'] . '" }';
else:
	echo '{ "alert": "error", "message": "' . $message['error'] . '&lt;br&gt;&lt;br&gt;**Reason:**&lt;br&gt;' . $mail-&gt;ErrorInfo . '" }';
endif;

} else {
echo '{ "alert": "error", "message": "' . $message['error_unexpected'] . '" }';
}

?>

AAnnaRosaSullivanAug 8, 2019

Let me know if you want me to send you the website and you can have a look yourself

SSemicolon WebSTAFFAug 10, 2019

Hello,

This looks like an error with your Server Configurations. Please provide us with a Live URL so that we can check out the exact issue and provide you with more assistance on this. Thanks for your Patience.

Additionally, it is Highly Recommended to use SMTP Functionality for your Forms for more reliable Email Delivery. For complete setup instructions, check the Documentation > Forms Section.

Meanwhile, do let us know if we can help you with anything else or if you find any further issues with Canvas.

AAnnaRosaSullivanAug 13, 2019

With the SMTP it wants the password.
Will this be 100% safe to put in, because my client have a lot of classified information

AAnnaRosaSullivanAug 13, 2019

Also my client is using an AOL email, how do I implement this into the SMTP?

SSemicolon WebSTAFFAug 13, 2019

Hello,

We have checked out your Websites and it appears to be a Server issue as your Server's PHP version is less than 5.6. Please make sure that you upgrade your Server's PHP engine to latest version and this issue will be resolved automatically.

Yes, using a SMTP Password is safe. As the PHP File is not readable publicly. We use it on Our Servers too. :) Or you can also consider setting up an Alternate Email specifically for this purpose.

You can check Google for the AOL SMTP Setup: https://www.google.co.in/search?q=aol+smtp

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

AAnnaRosaSullivanAug 15, 2019

Hi,

Thanks for your reply.

The Server’s PHP have been updated to the latest but it's still not working for some reason

I have attached screenshots (I have removed the email passwords for privacy but still in the code on website)

AAnnaRosaSullivanAug 15, 2019

The Error msg

AAnnaRosaSullivanAug 15, 2019

I know you have updated the website so I take it that include/sendmail.php have been replaced with include/form.php?

AAnnaRosaSullivanAug 15, 2019

Just an update

I removed the sendemail.php file completely and Allowed apps that use less secure sign-in in our aol email settings

I am trying to get the SMTP to work but still no luck (Attached screenshot and also error msg)

SSemicolon WebSTAFFAug 15, 2019

Hello,

The $toemails and $fromemail Code Blocks have been commented out in your Codes which is causing this issue. Make sure that you follow the Documentation > Forms Section to avoid any issues.

Also, if the SMTP is not working, you will need to use another SMTP Service as it is likely that AOL is block this.

Hope this Helps!

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