Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

PHP Mail is Not working

im using PHP mailer with gmail SMTP server settings for Send an Email on Form Submission using PHP with PHPMailer
but it showing There is an Error
where can i find what error is it

Comments

  • edited March 29
    <?php
    //index.php
    
    $error = '';
    $name = '';
    $email = '';
    $subject = '';
    $message = '';
    
    function clean_text($string)
    {
        $string = trim($string);
        $string = stripslashes($string);
        $string = htmlspecialchars($string);
        return $string;
    }
    
    if(isset($_POST["submit"]))
    {
        if(empty($_POST["name"]))
        {
            $error .= '<p><label class="text-danger">Please Enter your Name</label></p>';
        }
        else
        {
            $name = clean_text($_POST["name"]);
            if(!preg_match("/^[a-zA-Z ]*$/",$name))
            {
                $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
            }
        }
        if(empty($_POST["email"]))
        {
            $error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
        }
        else
        {
            $email = clean_text($_POST["email"]);
            if(!filter_var($email, FILTER_VALIDATE_EMAIL))
            {
                $error .= '<p><label class="text-danger">Invalid email format</label></p>';
            }
        }
        if(empty($_POST["subject"]))
        {
            $error .= '<p><label class="text-danger">Subject is required</label></p>';
        }
        else
        {
            $subject = clean_text($_POST["subject"]);
        }
        if(empty($_POST["message"]))
        {
            $error .= '<p><label class="text-danger">Message is required</label></p>';
        }
        else
        {
            $message = clean_text($_POST["message"]);
        }
        if($error == '')
        {
            require 'class/class.phpmailer.php';
            $mail = new PHPMailer;
            $mail->IsSMTP();                                //Sets Mailer to send message using SMTP
            $mail->Host = 'smtp.gmail.com';     //Sets the SMTP hosts of your Email hosting, this for Godaddy
            $mail->Port = '587';                                //Sets the default SMTP server port
            $mail->SMTPAuth = true;                         //Sets SMTP authentication. Utilizes the Username and Password variables
            $mail->Username = 'nikhil.jun15@gmail.com';                 //Sets SMTP username
            $mail->Password = '*************';                  //Sets SMTP password
            $mail->SMTPSecure = 'tsl';                          //Sets connection prefix. Options are "", "ssl" or "tls"
            $mail->From = $_POST["email"];                  //Sets the From email address for the message
            $mail->FromName = $_POST["name"];               //Sets the From name of the message
            $mail->AddAddress('info@inturealty.ga', 'Name');        //Adds a "To" address
            $mail->AddCC($_POST["email"], $_POST["name"]);  //Adds a "Cc" address
            $mail->WordWrap = 50;                           //Sets word wrapping on the body of the message to a given number of characters
            $mail->IsHTML(true);                            //Sets message type to HTML             
            $mail->Subject = $_POST["subject"];             //Sets the Subject of the message
            $mail->Body = $_POST["message"];                //An HTML or plain text message body
            if($mail->Send())                               //Send an Email. Return true on success or false on error
            {
                $error = '<label class="text-success">Thank you for contacting us</label>';
            }
            else
            {
                $error = '<label class="text-danger">There is an Error</label>';
            }
            $name = '';
            $email = '';
            $subject = '';
            $message = '';
        }
    }
    
    ?>
    

    php code validator is not showing any errors how to fix this i am new to php and in this web development please help me bro`

  • edited March 29

    please delete this total discussion

  • The variable $mail->ErrorInfo contains the error message returned by the SMTP connection. If that doesn't answer your question, you can also enable SMTP debug mode in PHP mailer to get more information about the connection.

    Also, you must reset your mailbox password immediately, as some may have already copied it. And remember to remove sensitive information from code first before copying it.

  • Thank you admin
    Please check http://inturealty.ga/index.php?i=1
    this at once give me some solution

  • @Inturi12 said:
    Thank you admin
    Please check http://inturealty.ga/index.php?i=1
    this at once give me some solution

    A solution to what? What is the problem? I don't even see any message.

This discussion has been closed.