Home Forums Porto Template contact-us-advanced.php form not processing the data

This topic contains 13 replies, has 2 voices, and was last updated by  Support2 6 months, 1 week ago. This post has been viewed 357 times

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #10028502

    louwaymoi
    Participant

    Hello Rodrigo,
    Thank you for your previous Help! 🙂
    I don’t understand this issue.
    I’m able to fill-up my form but when I submit it, it spin around and around and so on!
    unfortunately it doesn’t process anything in the background.
    Could you help me with this, please?
    That’s my 1st question! (below is my code)

    2nd Q.: How do I validate the type of attachment, ex.: .jpg, .png, .pdf, .doc, .docx, etc…?

    3rd Q.:How to place a limit on file size, ex.: 10 Mb and to validate it also, please?

    Here is my code for my 1st Question:

    <?php
    namespace IsoSlabContactQuoteForm;
    session_start();

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    require ‘../php/simple-php-captcha/simple-php-captcha.php’;
    require ‘../php/php-mailer/src/PHPMailer.php’;
    require ‘../php/php-mailer/src/SMTP.php’;
    require ‘../php/php-mailer/src/Exception.php’;

    // Step 1 – Enter your email address below.
    $email = ‘THISis@myemail.com’;

    // If the e-mail is not working, change the debug option to 2 | $debug = 2;
    $debug = 0;

    if(isset($_POST[’emailSent’])) {

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

    // Step 2 – If you don’t want a “captcha” verification, remove that IF.
    if (strtolower($_POST[‘captcha’]) == strtolower($_SESSION[‘captcha’][‘code’])) {

    // Step 3 – Configure the fields list that you want to receive on the email.
    $fields = array(
    0 => array(
    ‘text’ => ‘Name’,
    ‘val’ => $_POST[‘name’]
    ),
    1 => array(
    ‘text’ => ‘Email address’,
    ‘val’ => $_POST[’email’]
    ),
    2 => array(
    ‘text’ => ‘Phone’,
    ‘val’ => $_POST[‘phone’]
    ),
    3 => array(
    ‘text’ => ‘Information type’,
    ‘val’ => $_POST[‘info_type’]
    ),
    4 => array(
    ‘text’ => ‘Project Site’,
    ‘val’ => $_POST[‘project_site’]
    ),
    5 => array(
    ‘text’ => ‘Project Date’,
    ‘val’ => $_POST[‘project_date’]
    ),
    6 => array(
    ‘text’ => ‘Overall Dimension’,
    ‘val’ => $_POST[‘overall_dimension’]
    ),
    7 => array(
    ‘text’ => ‘Message’,
    ‘val’ => $_POST[‘message’]
    )
    );

    $message = ”;

    foreach($_POST as $label => $value) {
    if( !in_array( $label, array( ’emailSent’, ‘captcha’ ) ) ) {
    $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 3 (Optional) – If you don’t receive the email, try to configure the parameters below:

    $mail->IsSMTP(); // Set mailer to use SMTP
    $mail->Host = ‘smtp.someone.com’; // Specify main and backup server
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = ‘myemail@myemail.com’; // SMTP username
    $mail->Password = ‘TrytofindOut!LoL’; // SMTP password
    $mail->SMTPSecure = ‘tls’; // Enable encryption, ‘ssl’ also accepted
    $mail->Port = 587; // TCP port to connect to

    $mail->AddAddress($email); // Add a recipient

    //$mail->AddAddress(‘person2@domain.com’, ‘Person 2’); // Add another recipient
    //$mail->AddCC(‘person3@domain.com’, ‘Person 3’); // Add a “Cc” address.
    //$mail->AddBCC(‘person4@domain.com’, ‘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->info_type = $info_type;
    $mail->Body = $message;

    // Step 4 – 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());
    }

    } else {

    $arrResult = array (‘response’=>’captchaError’);

    }

    }
    ?>



    Template Version: 7.1
    #10028504

    Support2
    Keymaster

    Hello,

    1) Regarding the first issue, seems to be all right with your code. In that case we will need inspect your website online. Please send for us an online link with your website showing the issue, so we can inspect your code and try help you.

    2, 3) You can use the “additional methods” of validate plugin for the extension validation and a custom code for the filesize. For it please follow the instructions below:

    – First include on the page the additional methods script like the image below:

    – Then change the “Contact Form: Advanced” JS code inside the file (js/views/view.contact.js) to:

    /*
    Contact Form: Advanced
    */
    $.validator.addMethod('filesize', function (value, element, param) {
        return this.optional(element) || (element.files[0].size <= param)
    }, 'File size must be less than {0}mb');
    
    $('#contactFormAdvanced').validate({
    	onkeyup: false,
    	onclick: false,
    	onfocusout: false,
    	rules: {
    		'captcha': {
    			captcha: true
    		},
    		'checkboxes[]': {
    			required: true
    		},
    		'radios': {
    			required: true
    		},
    		attachment: {
                required: true,
                extension: "jpg|jpeg|png|pdf|doc|docx",
                filesize: 5,
            }
    	},
    	errorPlacement: function(error, element) {
    		if (element.attr('type') == 'radio' || element.attr('type') == 'checkbox') {
    			error.appendTo(element.closest('.form-group'));
    		} else {
    			error.insertAfter(element);
    		}
    	}
    });

    * You can change the filesize value at option filesize: 5 and the extension on the option extension.

    Please, try that and let us know if you need further assistance.

    Kind Regards,

    Rodrigo.


    #10028507

    louwaymoi
    Participant
    This reply has been marked as private.
    #10028533

    Support2
    Keymaster

    Hello Jocelyn,

    We made a test in your website contact form and for now the issue is the missing file “php/contact-form-verify-captcha.php” inside the folder “/php”. This is the file that makes the captcha validation.

    Just send the file “php/contact-form-verify-captcha.php” to your server.

    Regarding the HTML code for the attachment field, yes this code also will works.

    Please, try that and let us know if you need further assistance.

    Kind Regards,

    Rodrigo.


    #10028536

    louwaymoi
    Participant

    Hello Rodrigo,

    Thank you for your answers but I looked inside my ../PHP/ folder and I have all the same folders and sub-files & folders that you sold me with your theme!
    “php/contact-form-verify-captcha.php” is on my server since day one!
    Sorry for this sad news!

    Another question while you there please: This is my English version of that page and I will have a French one, my question is: will I have to put in in a new folder like PHPmailer-fr for the French version of the same page?

    How does it work and what does it do when we use the phpmailer.lang-fr.php?

    Thank you for your help!

    Jocelyn


    #10028539

    louwaymoi
    Participant

    Sorry I forgot this also! (with the previous post)

    Why “PHPMailerAutoload.php” is not part of php-mailer Folder from Theme version 7.1 and up anymore?
    It is not a necessary file to run the advanced contact form?

    And which process is calling this file: “contact-form-verify-captcha.php”

    Thank you for your patience and your help!

    Jocelyn


    #10028547

    Support2
    Keymaster
    This reply has been marked as private.
    #10028566

    louwaymoi
    Participant

    Hi again Rodrigo,

    First, Thank you for the above answers! 🙂

    I did the changes but:
    I got an error message:
    Error! There was an error sending your message.
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    And they are saying that the following file is missing : “../vendor/autoload.php” (it is not where they mention it is suppose to be!

    Can you supply me that missing file please?

    Thank you,

    Jocelyn


    #10028571

    Support2
    Keymaster
    This reply has been marked as private.
    #10028595

    Support2
    Keymaster
    This reply has been marked as private.
    #10028610

    louwaymoi
    Participant

    Hi Rodrigo,

    Thanks again for your help on the search yesterday!

    I did some tests and finally I had to call my supplier about the servers, we spent 2 hours over the phone and the problem is partially closed!

    I am able to use only the email to send with my for form with attachment wit a success message but we have a problem in the mail box showing the body of the email unless we log off and re-log in then we see everything then. It’s a server issue, they will get back to me!

    The SMTP protocol is now working, they initially gave me some wrong information for the Host, SMTPSecure = ”, then the Port was 25.
    Unfortunately, inside the inbox we still have the same problem as above. Server issue!!!!

    Questions:
    Why in the Head of the email that I receive when I send the form, I see my email (‘info@c-sxxxxxr.cxxxxm’) at the From: and the TO: location.
    where in my form I have to modify properly those Values?

    How do I insert empty line between each line of text so it is no too dense in the email?

    Can I change the subject line here :
    if(isset($_POST[’emailSent’])) {
    // 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′;
    With:
    3 => array(
    text’ => ‘Information type’,
    ‘val’ => $_POST[‘info_type’]
    ),
    I do the changes here in my ‘contact-quote.php’ form or in the other form on line 29?
    By the way, I don’t understand the relation between the 2 forms about the subject line?

    Thank you very much for your Help!!! 🙂

    Jocelyn


    #10028616

    Support2
    Keymaster

    Hello Jocelyn,

    Great that you figured it out about server issues.

    Regarding your questions:

    1) You can change the FROM here:

    $mail->SetFrom($email, $fromName);

    Regarding the TO, this is unchangeable and should appear the email defined on variable $email (the email that will receive the contacts).

    2) For add a new break line, change the $message variable code to:

    $message .= $label.": " . htmlspecialchars($value, ENT_QUOTES) . "<br><br>\n";

    3) Just change the subject to:

    $subject = $_POST['info_type'];
    
    or more customizable
    
    $subject = 'Email received about: '. $_POST['info_type'];

    Kind Regards,

    Rodrigo.


    #10028638

    louwaymoi
    Participant

    Hello Rodrigo,

    Thank you for your awesome help you are providing me!

    In your last answers, it seems they don’t work or I don’t understand them! LOL

    The #1 about the From:
    This is what I have from the beginning:
    // 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);

    The ID and the name of the email in the form is “email”.(FYI)
    Normally at the top of the email when I receive it, I should have the Name of the person who filled up the form with his email next to it, no?
    But now, I have his name with MY email next to him!

    The #2 worked Great, Thank you!

    The #3 about the subject is not working:
    This what I changed, is this OK?

    // 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’;
    $subject = ‘Email received about: ‘. $_POST[‘info_type’];

    Because both choices you gave me are not working!
    When I receive the email, it say NO subject in the left corner underneith the sender’s name!

    BTW, at which level in the code of my contact form, the french one, I slide in the : $mail->setLanguage(‘fr’); ???
    Between which lines exactly?

    Thank you!

    Jocelyn


    #10028654

    Support2
    Keymaster

    Hello,

    Regarding the #1 question:
    – We don’t recommend use submitter’s email address as the From address. It’s forgery and will usually mean you get rejected for SPF violations or end up in spam folders.

    But even so you want to do that, you can try with the code below:

    $mail->SetFrom($_POST['email'], $fromName);

    Regarding #3:
    – This code is correctly. Check if you are adding the subject to the email:

    Here is where you need add the language code:

    $mail = new PHPMailer(true);
    
    $mail->setLanguage('fr');// If not works, maybe you need define the language folder. In that case use the code below
    
    $mail->setLanguage('fr', 'php-mailer/language/');

    Kind Regards,

    Rodrigo.


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