1

https://bpaste.net/show/557a8418f211

That link includes the error i am getting. It seems that i am missing a closing bracket somewhere and i can't figure it out. When i added the closing bracket to the main if statement it gives me an error in the closing PHP tag. When i remove it i get an error on that line.

[root@li71-58 html]# php testmail.php

PHP Warning: Zend OPcache huge_code_pages: madvise(HUGEPAGE) failed: Invalid argument (22) in Unknown on line 0 PHP Parse error: syntax error, unexpected end of file in /var/www/html/testmail.php on line 70 [root@li71-58 html]#

Community
  • 1
  • 1
nicholascox2
  • 45
  • 1
  • 10
  • may i know why need this code in else part (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor']) && isset($_POST['descr'])); { – JYoThI Jun 30 '17 at 08:49

1 Answers1

1

you have left a brace after else now use this code

<?php
            // define variables and set to empty values
            $lnameErr = $emailErr = $fnameErr =  "";
            $fname = $emailaddr = $lname = $phone  = "";

            if ($_SERVER["REQUEST_METHOD"] == "POST") {
                    if (empty($_POST["fname"])) {
                            $fnameErr = "First name is required";
                    }
                    else {
                            $fname = test_input($_POST["fname"]);
        // check if name only contains letters and whitespace for first name
                            if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
                                    $nameErr = "Only letters and white space allowed";
                            }
                    }

                    if (empty($_POST["lname"])) {
                            $lnameErr = "Last name is required";
                    }
                    else {
                            $lname = test_input($_POST["lname"]);
        // check if name only contains letters and whitespace for last name
                            if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {
                                    $lnameErr = "Only letters and white space allowed";
                            }
                    }


                    if (empty($_POST["email"])) {
                            $emailErr = "Email is required";
                    }
                    else {
                            $email = test_input($_POST["email"]);
        // check if e-mail address is well-formed
                            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                                    $emailErr = "Invalid email format";
                            }
                    }

            }

        // Passes input to email

            else {
                    (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
                    && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
                    && isset($_POST['descr'])); {

                    $data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
                    $_POST['email'] . "\n" . $_POST['phone'] . "\n" .
                    $_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";


                    mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
            }
            }



            function test_input($data) {
                    $data = trim($data);
                    $data = stripslashes($data);
                    $data = htmlspecialchars($data);
                    return $data;
            }

            echo "Thank you for your inquery! <br/> An estimator will be with right with you";

    ?>

this is where you missed the curly brace

// Passes input to email

            else {
                    (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email'])
                    && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor'])
                    && isset($_POST['descr'])); {

                    $data = $_POST['firstname'] . ' ' . $_POST['lastname'] . "\n" .
                    $_POST['email'] . "\n" . $_POST['phone'] . "\n" .
                    $_POST['county'] . "\n" . $_POST['floor'] . "\n" . $_POST['descr'] . "\n";


                    mail('craftsllc1@gmail.com', 'Estimation Inquery', $data);
            }
            } // this is brace you missed
Prags
  • 811
  • 5
  • 17
  • Which else statement was missing it? i ran your code and it actually passed through. Now i just got to fix those Undefined index errors – nicholascox2 Jun 30 '17 at 08:47
  • may i know why need this code in else part (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['county']) && isset($_POST['floor']) && isset($_POST['descr'])); { – JYoThI Jun 30 '17 at 08:48
  • JYoThl it creates the variable needed for those post objects. I should have just set them as regular variables but i found that a little easier to understand since i'm new – nicholascox2 Jun 30 '17 at 08:50
  • I have upated the answer to show where you have missed the curly brace @user3765758 – Prags Jun 30 '17 at 08:50
  • I was running up and down that trying to figure out where it was. I completely forgot i had a statement for the $data – nicholascox2 Jun 30 '17 at 08:53
  • your logic is not correct . else part only run when method is not post . so while how did you get the value from $_POST['phone'] . @user3765758 – JYoThI Jun 30 '17 at 08:59
  • I haven't set validation. On the website the user can enter a phone number and that gets passed through. I was trying to get the email validator and fname/lname first – nicholascox2 Jun 30 '17 at 09:01