skip to Main Content

my problem is when i click the submit button it does submit the form and i don’t receive any problems on the website or inside of the console.Only changes i made to my code was editing the php part which was creating table i dont know it thats triggers the issue. But somehow i don’t receive any mail after i click the submit button. Can you guys please help me through this problem?

HTML CODES
    <div class="container contact-form-container text-center">
        <div class="row">
            
            <form method="post" action="php/process.php">
    
            <div class="col-12">
                <p class="contact-form-title">CONTACT US</p>
            </div>
    
            <div class="col-12 contact-form-col">
                <div class="contact-form-div">
                    <label class="contact-form-label" for="first-name">First Name <span class="contact-form-span">*</span></label>
                    <input class="contact-form-input" type="text" id="first-name" name="first-name" required>
                </div>
                
                <div class="contact-form-div">
                    <label class="contact-form-label" for="surname">Surname <span class="contact-form-span">*</span></label>
                    <input class="contact-form-input" type="text" id="surname" name="surname" required>
                </div>
            </div>
            
            <div class="col-12 contact-form-col">
                <div class="contact-form-div">
                    <label class="contact-form-label" for="email">Email <span class="contact-form-span">*</span></label>
                    <input class="contact-form-input" type="text" id="email" name="email" required>
                </div>
                
                <div class="contact-form-div">
                    <label class="contact-form-label" for="phone-number">Phone Number <span class="contact-form-span">*</span></label>
                    <input class="contact-form-input" id="tel" type="text" id="phone-number" name="phone-number" placeholder="(+1) 123 456 789" required>
                </div>
            </div>  
            
            <div class="col-12 contact-form-col">
                <div class="contact-form-div">
                    <label class="contact-form-label" for="country">Country <span class="contact-form-span">*</span></label>
                    <input class="contact-form-input" type="text" id="country" name="country" value="United States" required>
                </div>
                
                <div class="contact-form-div">
                <label class="contact-form-label" for="state">State / Province  <span class="contact-form-span">*</span></label>
                <select class="contact-form-select" name="state" required>
                    <option value="" disabled selected>Select State</option>
                    <option value="AL">Alabama</option>
                    <option value="AK">Alaska</option>
                    <option value="AZ">Arizona</option>
                    <option value="AR">Arkansas</option>
                    <option value="CA">California</option>
                    <option value="CO">Colorado</option>
                    <option value="CT">Connecticut</option>
                    <option value="DE">Delaware</option>
                    <option value="DC">District Of Columbia</option>
                    <option value="FL">Florida</option>
                    <option value="GA">Georgia</option>
                    <option value="HI">Hawaii</option>
                    <option value="ID">Idaho</option>
                    <option value="IL">Illinois</option>
                    <option value="IN">Indiana</option>
                    <option value="IA">Iowa</option>
                    <option value="KS">Kansas</option>
                    <option value="KY">Kentucky</option>
                    <option value="LA">Louisiana</option>
                    <option value="ME">Maine</option>
                    <option value="MD">Maryland</option>
                    <option value="MA">Massachusetts</option>
                    <option value="MI">Michigan</option>
                    <option value="MN">Minnesota</option>
                    <option value="MS">Mississippi</option>
                    <option value="MO">Missouri</option>
                    <option value="MT">Montana</option>
                    <option value="NE">Nebraska</option>
                    <option value="NV">Nevada</option>
                    <option value="NH">New Hampshire</option>
                    <option value="NJ">New Jersey</option>
                    <option value="NM">New Mexico</option>
                    <option value="NY">New York</option>
                    <option value="NC">North Carolina</option>
                    <option value="ND">North Dakota</option>
                    <option value="OH">Ohio</option>
                    <option value="OK">Oklahoma</option>
                    <option value="OR">Oregon</option>
                    <option value="PA">Pennsylvania</option>
                    <option value="RI">Rhode Island</option>
                    <option value="SC">South Carolina</option>
                    <option value="SD">South Dakota</option>
                    <option value="TN">Tennessee</option>
                    <option value="TX">Texas</option>
                    <option value="UT">Utah</option>
                    <option value="VT">Vermont</option>
                    <option value="VA">Virginia</option>
                    <option value="WA">Washington</option>
                    <option value="WV">West Virginia</option>
                    <option value="WI">Wisconsin</option>
                    <option value="WY">Wyoming</option>
                </select>
                </div>
            </div>  
    
            <div class="col-12 contact-form-col">
                <div class="contact-form-div">
                    <label class="contact-form-label" for="company-name">Company Name</label>
                    <input class="contact-form-input" type="text" id="company-name" name="company-name">               
                </div>
                
                <div class="contact-form-div">
                    <label class="contact-form-label" for="how-did-you-hear-about-us">How Did You Hear About Us?</label>
                    <input class="contact-form-input" type="text" id="how-did-you-hear-about-us" name="how-did-you-hear-about-us">
                </div>
            </div>  
    
            <div class="col-12 contact-form-col">
                <div class="contact-form-div">
                    <label class="contact-form-label" for="tell-us-about-your-project">Tell Us About Your Project?</label>
                    <textarea class="contact-form-textarea" id="tell-us-about-your-project" name="tell-us-about-your-project" rows="5" cols="90%"></textarea>             
                </div>
            </div>  
    
            <div class="submit-button-div">
                <div class="col-6 contact-form-col">
                    <div class="contact-form-div">
                        <input class="contact-form-submit-button" type="submit" value="Submit">   
                    </div>
                </div>  
            </div>
    
        </form>
    
        <?php
    if (isset($_GET['email']) && isset($_GET['status'])) {
        if ($_GET['email'] == 'send') {
            if ($_GET['status'] == 'ok') {
                echo '<script>';
                echo 'if (!localStorage.getItem("refreshed")) {';
                echo '  localStorage.setItem("refreshed", "true");';
                echo '  alert("Email send success");';
                echo '  window.location.reload();';
                echo '}';
                echo '</script>';
            } elseif ($_GET['status'] == 'no') {
                echo '<script>alert("Email send error");</script>';
            }
        }
    }
    ?>
    
        </div>
    </div>
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    <script>
    var inputEl = document.getElementById('tel');
    var goodKey = '0123456789+ ';
    
    var checkInputTel = function(e) {
      var key = (typeof e.which == "number") ? e.which : e.keyCode;
      var start = this.selectionStart,
        end = this.selectionEnd;
    
      var filtered = this.value.split('').filter(filterInput);
      this.value = filtered.join("");
    
      /* Prevents moving the pointer for a bad character */
      var move = (filterInput(String.fromCharCode(key)) || (key == 0 || key == 8)) ? 0 : 1;
      this.setSelectionRange(start - move, end - move);
    }
    
    var filterInput = function(val) {
      return (goodKey.indexOf(val) > -1);
    }
    
    inputEl.addEventListener('input', checkInputTel);
    </script>
    
    <script>
    var uploadField = document.getElementById("file-size");
    
    uploadField.onchange = function() {
        if(this.files[0].size > 50000000){
           alert("File is too big!");
           this.value = "";
        };
    };
    </script>


PHP CODES

    enter code here<?php

require 'vendor/autoload.php';

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;

$mail = new PHPMailer(true);

if (isset($_POST['email'])) {
    try {
        $html = "<table>";

        $html .= '<tbody>';
        $html .= '<tr>';
        $html .= '<th>Full Name: </th>';
        $html .= '<td>' . $_POST['first-name'] . ' ' . $_POST['surname'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>Email: </th>';
        $html .= '<td>' . $_POST['email'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>Phone Number: </th>';
        $html .= '<td>' . $_POST['phone-number'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>Country: </th>';
        $html .= '<td>' . $_POST['country'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>State / Province: </th>';
        $html .= '<td>' . $_POST['state'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>Company Name: </th>';
        $html .= '<td>' . $_POST['company-name'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>How Did You Hear About Us?: </th>';
        $html .= '<td>' . $_POST['how-did-you-hear-about-us'] . '</td>';
        $html .= '</tr>';

        $html .= '<tr>';
        $html .= '<th>Tell Us About Your Project: </th>';
        $html .= '<td>' . nl2br($_POST['tell-us-about-your-project']) . '</td>';
        $html .= '</tr>';

        // Add code for handling file attachment here

        $html .= '</tbody>';
        $html .= "</table>";

        $mail->SMTPDebug = SMTP::DEBUG_SERVER | SMTP::DEBUG_CLIENT;
        $mail->isSMTP();
        $mail->SMTPDebug = 3;
        $mail->Host = 'localhost';
        $mail->Port = 25;
        $mail->SMTPAuth = false;
        $mail->SMTPSecure = false;
        $mail->SMTPAutoTLS = false;

        $mail->setFrom('[email protected]', 'no-name');
        $mail->addAddress('[email protected]');
        $mail->isHTML(true);

        $mail->addReplyTo($_POST['email'], $_POST['name']);

        $mail->Subject = $_POST['subject'];
        $mail->Body = $html;

        $response = $mail->send();

        if ($response) {
            header('Location: https://www.demo.com/');
        } else {
            echo $response;
        }
    } catch (Exception $e) {
        echo $mail->ErrorInfo;
    }
}

?>

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution

    The Code Before

     $mail->Subject = $_POST['subject'];
    

    The New Code

    $mail->Subject = $_POST['New Mail From Website'];
    

    I think google was blocking it because of the title. At the moment its working.


  2. Have 2 thing in mind.

    First, you need to check that your display_errors and error_reporting in php.ini are set currently, so you can see the errors if they happened.

    Second, it’s better to test your code in real host or server or at least use Gmail free SMTP server, so you can diagnose that the problem is about code or server.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search