Contact form is not working!

Home Forums Porto – Responsive HTML5 Template Contact form is not working!

  • This topic has 7 replies, 2 voices, and was last updated 1 month ago by Support. This post has been viewed 179 times
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #10045164
    Marvinbb
    Participant

    Hello My contact form is not working. I tried everything the documentation says and nothing! I spent hours and can’t figure it out. I don’t understand what the problem is! My website is live, can you please rise the level of this ticket to high please?

    Thank you!


    #10045166
    Support
    Keymaster
    This reply has been marked as private.
    #10045167
    Marvinbb
    Participant

    I see! I was also trying to use the SMTP but that was not working as well. I was using Gmail and all the credentials were correct but it still not worked. Can you please help me with the SMTP way of sending emails? I’d really appreciate it. Can you trouble shoot it on your end using Gmail? Thanks you


    #10045168
    Support
    Keymaster

    We stopped using the Gmail contact form because the result is not good, very unstable, it works sometimes and only with some emails, so we do not recommend it.

    Create that new email in your server with the same domain and use this PHP file: php/contact-form.php

    <?php
    /*
    Name: 			Contact Form
    Written by: 	Okler Themes - (http://www.okler.net)
    Theme Version:	11.1.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 = '';
    
    // If the e-mail is not working, change the debug option to 2 | $debug = 2;
    $debug = 1;
    
    // 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.": " . nl2br(htmlspecialchars($value, ENT_QUOTES)) . "<br>";
    }
    
    $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
    	//$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);
    
    	// Reply To
    	if( isset($_POST['email']) && !empty($_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;
    
    	// Step 3 - If you don't want to attach any files, remove that code below
    	if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] == UPLOAD_ERR_OK) {
    		$mail->AddAttachment($_FILES['attachment']['tmp_name'], $_FILES['attachment']['name']);
    	}
    
    	$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);
    }

    Change only line 23. Let me know when you do it so I can debug with the browser dev tools.


    #10045169
    Marvinbb
    Participant

    Ok, so i have an email already that has always been used. I added it to line 23.
    It’s [email protected]


    #10045170
    Support
    Keymaster

    Did you receive the test e-mail I just sent to that email?

    If you don’t, you may have to confirm with your host provider what are the SMTP setting to send e-mail with PHP form. They may be blocking that too.


    #10045171
    Marvinbb
    Participant

    Hey, I did received it but I get an error on the form after sending.


    #10045172
    Support
    Keymaster

    Try changing $debug = 1; to $debug = 0;


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

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