Problem with the email

3 replies · opened Nov 12, 2020

RRochanakNov 12, 2020

Hello,
I have problem with my email,

I have already posted a comment, and I have received the following reply :

The Codes you are using in the include/sendemail.php File appears to have some Markup errors as it returns a 500 Internal Server Error: https://www.danceheads.fr/include/sendemail.php even before submitting. You can check the related errors by simply adding the following code at the top of this File:
error_reporting(E_ALL);

I followed the instructions above, and here is the result:

  • I replaced the "phpmailer file" with the newest version
  • contact page: I changed "action="include/sendemail.php" to "action="include/form.php" since in the new version there is no more sendemail.php

At the top of the "form.php" file, I added the following line:

"error_reporting(R_ALL)" , the result was a blank page.

So instead I added the following lines:
ini_set('display_startup_errors', true);
error_reporting(E_ALL);
ini_set('display_errors', true);
A message is displayed : { "alert": "error", "message": "An unexpected error occured. Please Try Again later." }

When I try to send an email from the contact form, a message is displayed :
Bot Detected ! Form could not be processed ! Please Try Again !

This is my smtp code added to "form.php" which has been given to me by the hosting company, their test on my website it's ok so the problem is not from their side :

$mail = new PHPMailer();
/* Add your SMTP Codes after this Line */
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'mail.flexone.cloud';
$mail->SMTPAuth = true;
$mail->Username = 'XXXXXXXXX';
$mail->Password = 'XXXXXXXXX';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
// End of SMTP

Please I need your help, I tried many different solutions, but I didn't succeed.
I've been using canvas for 4 years, never had a problem with the forms, suddenly the hosting company decided to use smtp, so please help me.

Thank you in advance

RRochanakNov 12, 2020

<!-- Contact Form
============================================= -->
<div class="col_half">

					&lt;div class="fancy-title title-dotted-border"&gt;
						&lt;h1&gt;NOUS CONTACTER&lt;/h1&gt;
					&lt;/div&gt;

					&lt;div class="contact-widget"&gt;

						&lt;div class="contact-form-result"&gt;&lt;/div&gt;

						&lt;form class="nobottommargin" id="template-contactform" name="template-contactform" action="include/form.php" method="post"&gt;

							&lt;div class="form-process"&gt;&lt;/div&gt;

							&lt;div class="col_one_third"&gt;
								&lt;label for="template-contactform-name"&gt;Nom &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="sm-form-control required" /&gt;
							&lt;/div&gt;

							&lt;div class="col_one_third"&gt;
								&lt;label for="template-contactform-email"&gt;Email &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email sm-form-control" /&gt;
							&lt;/div&gt;

							&lt;div class="col_one_third col_last"&gt;
								&lt;label for="template-contactform-phone"&gt;TELEPHONE &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="text" id="template-contactform-phone" name="template-contactform-phone" value="" class="sm-form-control required" /&gt;
							&lt;/div&gt;
                            

							&lt;div class="clear"&gt;&lt;/div&gt;

							&lt;div class="col_two_third"&gt;
								&lt;label for="template-contactform-subject"&gt;Objet &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="text" id="template-contactform-subject" name="template-contactform-subject" value="" class="required sm-form-control" /&gt;
							&lt;/div&gt;

							&lt;div class="clear"&gt;&lt;/div&gt;

							&lt;div class="col_full"&gt;
								&lt;label for="template-contactform-message"&gt;Message &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;textarea class="required sm-form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30"&gt;&lt;/textarea&gt;
							&lt;/div&gt;

							&lt;div class="col_full hidden"&gt;
								&lt;input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control" /&gt;
							&lt;/div&gt;

							&lt;div class="col_full"&gt;
								&lt;button name="submit" type="submit" id="submit-button" tabindex="5" value="Submit" class="button button-3d nomargin"&gt;SOUMETTRE&lt;/button&gt;
							&lt;/div&gt;

						&lt;/form&gt;
					&lt;/div&gt;

				&lt;/div&gt;&lt;!-- Contact Form End --&gt;
RRochanakNov 12, 2020

<?php

ini_set('display_startup_errors', true);
error_reporting(E_ALL);
ini_set('display_errors', true);

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

Form Processor Plugin
by SemiColonWeb

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

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

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();

$toemails[] = array(
'email' => 'danceheas@danceheads.fr', // Your Email Address
'name' => 'danceheads' // Your Name
);

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

$fromemail = array(
'email' => 'danceheas@danceheads.fr', // Company's Email Address (preferably currently used Domain Name)
'name' => 'Dance Heads' // 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 */
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'mail.flexone.cloud'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'danceheads@danceheads.fr'; // SMTP username
$mail->Password = 'xxxxxxxxxx'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; PHPMailer::ENCRYPTION_SMTPS encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for PHPMailer::ENCRYPTION_SMTPS above
// 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.'
);

/-------------------------------------------------
Blocked Words from Forms
---------------------------------------------------
/

$spam_keywords = array(
'viagra',
'cialis',
'levitra'
);

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

/*-------------------------------------------------
	SPAM Protection
---------------------------------------------------*/

function spam_keyword_check( $submitted, $spamwords ) {
	if( !is_array( $spamwords ) ) $spamwords = array( $spamwords );
	foreach( $spamwords as $spamstring ) {
		if( ( $position = stripos( $submitted, $spamstring ) ) !== false ) return $position;
	}
	return false;
}

foreach( $submits as $spam_submit ) {
	if( spam_keyword_check( $spam_submit, $spam_keywords ) ) {
		// A successful message is displayed to the submitter that makes him think that the Form has been sent so that he cannot modify the keywords to prevent SPAM
		echo '{ "alert": "success", "message": "' . $message['success'] . '" }';
		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 = mb_convert_case( $name, MB_CASE_TITLE, "UTF-8" );

	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 );
$mail-&gt;CharSet = "UTF-8";
$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'] . '" }';
}

?>

SSemicolon WebSTAFFNov 13, 2020

Hello,

Thanks for your Patience!

Upon checking your Codes, it appears that you are partially updating the Canvas Codes for your Website. It is recommended to completely Update to the Latest Version of Canvas to avoid any unexpected issues. You will need to update the JS/HTML/PHP Files completely according to the Latest Versions.

The issue regarding Bot Detected is because in your Form there is no botcheck field as there is in the Default Forms provided with the Latest Package Files. The BotCheck Field helps in preventing SPAM to an extent and highly recommended to prevent BOT Spams. Simply add this Field and this issue should be resolved. Consider checking the Documentations for the Forms: http://docs.semicolonweb.com/docs/forms/form-setup/ completely or other Components before editing them to fully understand their functionalities.

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