Form with google reCAPTCHA and multiple file upload

19 replies · opened Nov 29, 2016

SsasidarNov 29, 2016

Hello
i have just managed to create a onepage using your theme, where in i have a form record, i want to achieve the following

  1. multple file upload ( when i choose multiple files and send only the last file is getting attached)
  2. when reCAPTCHA is included ( i have added the secret code, etc) into the sendmail.php, but when the form is submitted it continues to show as if the form is processing but no mails are coming or confirmation of receiving email is also not displaying
  3. how do i use company gmail smtp to send mails as many of the mails send through php mailer goes to spam folder
    i want your help in sorting the above from you

URL : www.call2translate.com.my

regards
Sasidar

SsasidarNov 30, 2016

Hi
I have sent this request yesterday and waiting for the update, are you there to help
appreciate your early response
thanks
Sasidar

SSemicolon WebSTAFFNov 30, 2016

Hello,

We Apologize about the Delays!

  1. Please find the following code in the include/sendemail.php File:
if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
	$mail->IsHTML(true);
	$mail->AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
}

and replace it with:

if ( isset( $_FILES['template-contactform-file'] ) ) {
	$mail->IsHTML(true);
	//Attach multiple files one by one
	for ($ct = 0; $ct addAttachment($uploadfile, $filename);
		}
	}
}

Additionally, also make sure that you have changed name="template-contactform-file" in the HTML to name="template-contactform-file[]".

  1. We have just tried checking out your Form and reCaptcha appears to be working fine on your Website.

  2. Please consider using this Example Code: https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps

Hope this Helps! Thanks for your Patience.

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

SsasidarDec 2, 2016

hi thanks for the mail. i have added as directed by you, but i am not able to choose multiple files now as i upload. i am only able to choose one file.
2. do you advise to use gmail smtp or php mailer

SSemicolon WebSTAFFDec 4, 2016

Hello,

  1. We have just checked out your Website and in Order to be able to Select Multiple Files, please use the following code for your File Input:
  1. You can use any Email Processor, both are fine. You can definitely use the Gmail SMTP on PHPMailer as mentioned in the examples above.

Hope this helps! Thanks for your Patience.

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

SsasidarDec 5, 2016

many thanks, i got it done
i want one more help
if you see www.call2translate.com.my next to services, i see 2 drop down icons, which i am unable to remove, must be a basic doubt when i do not know where to remove, can you help
thanks
sasidar

SSemicolon WebSTAFFDec 5, 2016

Hello,

We have just checked out your Website and there are some HTML Validation Errors on your Page: https://validator.w3.org/nu/?doc=http%3A%2F%2Fwww.call2translate.com.my%2F which might be the cause of this Issue. Please fix the Errors related to the Unclosed HTML Tags and Duplicate IDs and this should fix the issue.

Hope this Helps!

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

SsasidarDec 13, 2016

hi
please check this, not sure of my mistakes, we are not getting the mails. can you help me correct it thanks
sasidar
the web address is www.call2translate.com.sg

i want the forms to work with or without the attachments

SsasidarDec 13, 2016

<?php

require_once('phpmailer/PHPMailerAutoload.php');

$toemails = array();

$toemails[] = array(
'email' => 'sg-support@lyriclabs.com', // Your Email Address
'name' => 'Call2translate Singapore' // 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 = '6Lcq1AwUAAAAAKvR5VHRBwdrQfa77XuY29QPL9-Z'; // 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'] : '';
	$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
	$phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
	$subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
	$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';

	$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;

		$name = isset($name) ? "Name: $name&lt;br&gt;&lt;br&gt;" : '';
		$email = isset($email) ? "Email: $email&lt;br&gt;&lt;br&gt;" : '';
		$phone = isset($phone) ? "Phone: $phone&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 $email $phone $message $referrer";

		// Runs only when File Field is present in the Contact Form

if ( isset( $_FILES['template-contactform-file'] ) ) {
$mail->IsHTML(true);
//Attach multiple files one by one
for ($ct = 0; $ct < count($_FILES['template-contactform-file']['tmp_name']); $ct++) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['template-contactform-file']['name'][$ct]));
$filename = $_FILES['template-contactform-file']['name'][$ct];
if (move_uploaded_file($_FILES['template-contactform-file']['tmp_name'][$ct], $uploadfile)) {
$mail->addAttachment($uploadfile, $filename);
}
}
}

		// 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 WebSTAFFDec 14, 2016

Hello,

We have just checked out your Website testing the Contact Form and it definitely gives us a Successfully Sent Message. If you mean that despite getting the Successful Message, you are still not receiving the Emails, then this issue lies within your Server as the Codes you have provided is perfectly fine. Additionally, it is recommended to contact your Web Hosting Provider regarding this issue and ask them to enable the PHP mail() Function for your Server/Hosting as this will automatically fix the issue. Also, mention them that you are using PHPMailer. Thanks for your Patience.

Hope this Helps!

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

SsasidarJan 1, 2017

Dear Sir
Happy New Year
In www.call2translate.com.my inspite of the recpatcha, the spamming happens and when i asked the hosting company, they said the code allows to by pass the recpatcha, and thy tried to send a form directly and the mail is coming, so we get lot of spam content a form response.
can you kindly check the form and let me know what is wrong with it or how to make sure spamming does not happen
Happy New Year
regards
sasidar
PS. : --------- Forwarded message ----------
From: Root User <root@localhost>
Date: Sat, Dec 31, 2016 at 8:50 PM
Subject:
To: Call2translate Malaysia <my-support@lyriclabs.com>

Name:

Email: s

Phone:

Message: This is Suresh. bypassed the code

SsasidarJan 2, 2017

Dear Sir
i have another issue, not sure if this is on code or the hosting company
www.lyriclabs.com.my, the audio doesnt come on the 2nd slider video that we have..can you kindly check and let me know
thanks
sasidar

SsasidarJan 2, 2017

Sir
can you kindly reply asap
regards
sasidar

SsasidarJan 3, 2017

Dear sir
I am waiting for the issue for a couple of more days,
we need to prevent people accessing sendmail.php directly.
please help urently

SsasidarJan 3, 2017

dear sir
i am waiting

SSemicolon WebSTAFFJan 3, 2017

Hello,

Apologies for the Delay!

  1. To make the reCaptcha Mandatory, simply find the following code in the include/sendemail.php File:
// 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;
	}
}

and remove the If/Else Condition. So just replace the Above Code with the following code:

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

This will make the reCaptcha Mandatory and disallow unauthorized submission of the form. Hope this Helps! Thanks for your Patience.

  1. The Audio appears to be working for us for the Video. Can you please confirm?

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

SsasidarJan 8, 2017

Dear Sir
http://translators.com.sg/
in this quick contact form, i am getting a lot of spam messages, i think the 'bot check" is not working, how to ensure the "bot check" if working fine ro i can avoid spam mails
kindly reply faster
thanks
sasidar

SSemicolon WebSTAFFJan 9, 2017

Hello,

Apologies about the Inconveniences!

You can add the reCaptcha integration for the Quick Contact Form in the same way as the Primary Contact Form to prevent SPAM.

Hope this Helps!

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

SsasidarJan 30, 2017

Hi
we have multiple offices, can I show multiple locations in google page in contact.html. if yes how do i do that? the website is www.lyriclabs.in

SSemicolon WebSTAFFJan 31, 2017

Hello,

This is Definitely Possible and has already been explained in the Documentation > Shortcodes > Google Maps Section.

This will definitely work fine. 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