- This topic has 11 replies, 2 voices, and was last updated 5 years, 5 months ago by
Support. This post has been viewed 1968 times
-
AuthorPosts
-
February 7, 2021 at 1:17 am #10036034
odessitka1961
ParticipantHi, I am trying to set up a contact form using testing server, but it’s keeps giving me a red error, saying
“Error! There was an error sending your message.
Could not instantiate mail function.”My website isn’t life yet. I inserted into “contact-form”.php file email that I will use in my website. But it’s keeps giving me an error. Maybe it’s because my website isn’t life yet and the email address doesn’t exist yet. But, how I can make sure that my contact form is actually works? Please help me.
Thanks.
Taina
February 9, 2021 at 1:21 am #10036053Support
KeymasterHello Taina, thanks for your purchase.
You are right. The reason is your website is not live yet and the email don’t exists.
One way for testing is use Gmail account and setup the SMTP options (the step 2 at “php/contact-form.php”).
Follow the steps below:
1) First create gmail.com account.
2) In the google account settings, allow access for less security apps:
https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cif-less-secure-app-access-is-on-for-your-account3) Edit the “php/contact-form.php” at “Step 2” code like below:

Change username and password with your gmail account info.
We hope this helps and clarify!
Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
If you are satisfied with EZY HTML and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads
February 9, 2021 at 1:22 am #10036054Support
KeymasterHello,
Also please make sure to run your project trough a local server like APACHE or NGINX. Probably the best option is XAMPP:
https://www.apachefriends.org/download.htmlKind Regards,
Rodrigo.
If you are satisfied with EZY HTML and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads
February 9, 2021 at 3:01 am #10036066odessitka1961
ParticipantHi Rodrigo.
Thanks for your reply. Yes, I am running my project through “wamp64”. I am sorry, but I can’t understand what I should change in php/contact-form.php file. Here is the code for “Step 2” in contact-form.php
How I should change it? I am not very experienced in setting up and making changes in contact forms.// Step 2 (Optional) – If you don’t receive the email, try to configure the parameters below:
//$mail->IsSMTP(); // Set mailer to use SMTP
//$mail->Host = ‘mail.yourserver.com’; // Specify main and backup server
//$mail->SMTPAuth = true; // Enable SMTP authentication
//$mail->Username = ‘[email protected]’; // SMTP username
//$mail->Password = ‘secret’; // SMTP password
//$mail->SMTPSecure = ‘tls’; // Enable encryption, ‘ssl’ also accepted
//$mail->Port = 587; // TCP port to connect to$mail->AddAddress($email); // Add another recipient
//$mail->AddAddress(‘[email protected]’, ‘Person 2’); // Add a secondary recipient
//$mail->AddCC(‘[email protected]’, ‘Person 3’); // Add a “Cc” address.
//$mail->AddBCC(‘[email protected]’, ‘Person 4’); // Add a “Bcc” address.// From – Name
$fromName = ( isset($_POST[‘name’]) ) ? $_POST[‘name’] : ‘Website User’;
$mail->SetFrom($email, $fromName);// Repply To
if( isset($_POST[’email’]) ) {
$mail->AddReplyTo($_POST[’email’], $fromName);
}$mail->IsHTML(true); // Set email format to HTML
$mail->CharSet = ‘UTF-8’;
$mail->Subject = $subject;
$mail->Body = $message;$mail->Send();
$arrResult = array (‘response’=>’success’);} catch (Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->errorMessage());
} catch (\Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->getMessage());
}if ($debug == 0) {
echo json_encode($arrResult);
}
February 9, 2021 at 3:32 am #10036070Support
KeymasterHello Taina,
First make sure to have a gmail.com account created and with the option for allow less secure apps access enabled, like I explained in my first reply.
With your @gmail.com username and password in your hands, go to “php/contact-form.php” and change this:

To this:

* Change
YOUR_GMAIL_USERNAMEwith your @gmail.com username.
* ChangeYOUR_GMAIL_PASSWORDwith your @gmail.com account password.Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
If you are satisfied with EZY HTML and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads
February 9, 2021 at 4:49 am #10036071odessitka1961
ParticipantHi.
Sorry to say, but it’s still doesn’t work.
Here is my “contact-form.php”<?php
/*
Name: Contact Form
Written by: Okler Themes – (http://www.okler.net)
Theme Version: 8.2.0
*/namespace PortoContactForm;
session_cache_limiter(‘nocache’);
header(‘Expires: ‘ . gmdate(‘r’, 0));header(‘Content-type: application/json’);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;require ‘php-mailer/src/PHPMailer.php’;
require ‘php-mailer/src/SMTP.php’;
require ‘php-mailer/src/Exception.php’;// Step 1 – Enter your email address below.
$email = ‘[email protected]’; //this email address doesn’t exist yet// If the e-mail is not working, change the debug option to 2 | $debug = 2;
$debug = 0;// If contact form don’t has the subject input change the value of subject here
$subject = ( isset($_POST[‘subject’]) ) ? $_POST[‘subject’] : ‘Define subject in php/contact-form.php line 29’;$message = ”;
foreach($_POST as $label => $value) {
$label = ucwords($label);// Use the commented code below to change label texts. On this example will change “Email” to “Email Address”
// if( $label == ‘Email’ ) {
// $label = ‘Email Address’;
// }// Checkboxes
if( is_array($value) ) {
// Store new value
$value = implode(‘, ‘, $value);
}$message .= $label.”: ” . htmlspecialchars($value, ENT_QUOTES) . “<br>\n”;
}$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = $debug; // Debug Mode
// Step 2 (Optional) – If you don’t receive the email, try to configure the parameters below:
//$mail->IsSMTP(); // Set mailer to use SMTP
//$mail->Host = ‘mail.yourserver.com’; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘[email protected]’; // SMTP username this is my existing email address
$mail->Password = ‘**********’; // SMTP password
$mail->SMTPSecure = ‘tls’; // Enable encryption, ‘ssl’ also accepted
$mail->Port = 587; // TCP port to connect to$mail->AddAddress($email); // Add another recipient
//$mail->AddAddress(‘[email protected]’, ‘Person 2’); // Add a secondary recipient
//$mail->AddCC(‘[email protected]’, ‘Person 3’); // Add a “Cc” address.
//$mail->AddBCC(‘[email protected]’, ‘Person 4’); // Add a “Bcc” address.// From – Name
$fromName = ( isset($_POST[‘name’]) ) ? $_POST[‘name’] : ‘Website User’;
$mail->SetFrom($email, $fromName);// Repply To
if( isset($_POST[’email’]) ) {
$mail->AddReplyTo($_POST[’email’], $fromName);
}$mail->IsHTML(true); // Set email format to HTML
$mail->CharSet = ‘UTF-8’;
$mail->Subject = $subject;
$mail->Body = $message;$mail->Send();
$arrResult = array (‘response’=>’success’);} catch (Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->errorMessage());
} catch (\Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->getMessage());
}if ($debug == 0) {
echo json_encode($arrResult);
}
I still getting message:
“Error! There was an error sending your message.
Could not instantiate mail function.”
February 9, 2021 at 6:29 am #10036075Support
KeymasterHello,
Here’s the problem with your code:

– Remove these “//”.
– Also change “mail.yourserver.com” to “smtp.gmail.com”Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
If you are satisfied with EZY HTML and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads
February 9, 2021 at 7:07 am #10036076odessitka1961
ParticipantStill gives me an error, but a different one:
“Error! There was an error sending your message.
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting”Here is my contact-form.php
<?php
/*
Name: Contact Form
Written by: Okler Themes – (http://www.okler.net)
Theme Version: 8.2.0
*/namespace PortoContactForm;
session_cache_limiter(‘nocache’);
header(‘Expires: ‘ . gmdate(‘r’, 0));header(‘Content-type: application/json’);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;require ‘php-mailer/src/PHPMailer.php’;
require ‘php-mailer/src/SMTP.php’;
require ‘php-mailer/src/Exception.php’;// Step 1 – Enter your email address below.
$email = ‘[email protected]’;// If the e-mail is not working, change the debug option to 2 | $debug = 2;
$debug = 0;// If contact form don’t has the subject input change the value of subject here
$subject = ( isset($_POST[‘subject’]) ) ? $_POST[‘subject’] : ‘Define subject in php/contact-form.php line 29’;$message = ”;
foreach($_POST as $label => $value) {
$label = ucwords($label);// Use the commented code below to change label texts. On this example will change “Email” to “Email Address”
// if( $label == ‘Email’ ) {
// $label = ‘Email Address’;
// }// Checkboxes
if( is_array($value) ) {
// Store new value
$value = implode(‘, ‘, $value);
}$message .= $label.”: ” . htmlspecialchars($value, ENT_QUOTES) . “<br>\n”;
}$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = $debug; // Debug Mode
// Step 2 (Optional) – If you don’t receive the email, try to configure the parameters below:
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = ‘smtp.gmail.com’; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = ‘[email protected]’; // SMTP username
$mail->Password = ‘*******’; // SMTP password
$mail->SMTPSecure = ‘tls’; // Enable encryption, ‘ssl’ also accepted
$mail->Port = 587; // TCP port to connect to$mail->AddAddress($email); // Add another recipient
//$mail->AddAddress(‘[email protected]’, ‘Person 2’); // Add a secondary recipient
//$mail->AddCC(‘[email protected]’, ‘Person 3’); // Add a “Cc” address.
//$mail->AddBCC(‘[email protected]’, ‘Person 4’); // Add a “Bcc” address.// From – Name
$fromName = ( isset($_POST[‘name’]) ) ? $_POST[‘name’] : ‘Website User’;
$mail->SetFrom($email, $fromName);// Repply To
if( isset($_POST[’email’]) ) {
$mail->AddReplyTo($_POST[’email’], $fromName);
}$mail->IsHTML(true); // Set email format to HTML
$mail->CharSet = ‘UTF-8’;
$mail->Subject = $subject;
$mail->Body = $message;$mail->Send();
$arrResult = array (‘response’=>’success’);} catch (Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->errorMessage());
} catch (\Exception $e) {
$arrResult = array (‘response’=>’error’,’errorMessage’=>$e->getMessage());
}if ($debug == 0) {
echo json_encode($arrResult);
}
February 9, 2021 at 7:24 am #10036077odessitka1961
ParticipantI don’t know if it will help, but my DreamweaverCS6 shows me an error in file “php-mailer/src/SMTP.php” in the line 180. Here is that paragraph from line 180 to the line 188:
protected $smtp_transaction_id_patterns = [
‘exim’ => ‘/[\d]{3} OK id=(.*)/’,
‘sendmail’ => ‘/[\d]{3} 2.0.0 (.*) Message/’,
‘postfix’ => ‘/[\d]{3} 2.0.0 Ok: queued as (.*)/’,
‘Microsoft_ESMTP’ => ‘/[0-9]{3} 2.[\d].0 (.*)@(?:.*) Queued mail for delivery/’,
‘Amazon_SES’ => ‘/[\d]{3} Ok (.*)/’,
‘SendGrid’ => ‘/[\d]{3} Ok: queued as (.*)/’,
‘CampaignMonitor’ => ‘/[\d]{3} 2.0.0 OK:([a-zA-Z\d]{48})/’,
];
February 9, 2021 at 7:32 am #10036078odessitka1961
ParticipantSorry, I noticed yet another error in “php-mailer/src/PHPMailer.php” file. My DreamweaverCS6 shows me an error in in the line 166. Maybe it will help to solve the problem. Here is that paragraph from line 166 to the line 175:
protected static $IcalMethods = [
self::ICAL_METHOD_REQUEST,
self::ICAL_METHOD_PUBLISH,
self::ICAL_METHOD_REPLY,
self::ICAL_METHOD_ADD,
self::ICAL_METHOD_CANCEL,
self::ICAL_METHOD_REFRESH,
self::ICAL_METHOD_COUNTER,
self::ICAL_METHOD_DECLINECOUNTER,
];
February 9, 2021 at 9:03 am #10036080odessitka1961
ParticipantHi. I’ve done it!!!! Finally the green success message and yes, I received message from my contact form on my gmail address!!!!!
Success! Your message has been sent to us.
Thank you very much for your help!!! 🙂
February 9, 2021 at 11:22 pm #10036089Support
KeymasterHello,
Great! 🙂
If you need further assistance, feel free to contact us.
Kind Regards,
Rodrigo.
If you are satisfied with EZY HTML and our support, please leave your comment and rating on ThemeForest downloads page. That helps us a lot: https://themeforest.net/downloads
-
AuthorPosts
This topic is marked as "RESOLVED" and can not rceive new replies.