contact form problem

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #10036034
    odessitka1961
    Participant

    Hi, 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


    #10036053
    Support
    Keymaster

    Hello 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-account

    3) 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


    #10036054
    Support
    Keymaster

    Hello,

    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.html

    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


    #10036066
    odessitka1961
    Participant

    Hi 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);
    }


    #10036070
    Support
    Keymaster

    Hello 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_USERNAME with your @gmail.com username.
    * Change YOUR_GMAIL_PASSWORD with 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


    #10036071
    odessitka1961
    Participant

    Hi.
    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.”


    #10036075
    Support
    Keymaster

    Hello,

    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


    #10036076
    odessitka1961
    Participant

    Still 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&#8221;

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


    #10036077
    odessitka1961
    Participant

    I 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})/’,
    ];


    #10036078
    odessitka1961
    Participant

    Sorry, 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,
    ];


    #10036080
    odessitka1961
    Participant

    Hi. 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!!! 🙂


    #10036089
    Support
    Keymaster

    Hello,

    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


Viewing 12 posts - 1 through 12 (of 12 total)

This topic is marked as "RESOLVED" and can not rceive new replies.