-1

I recently created a contact form with php as well but everytime I click submit, I only get an undefined error, nothing else. Can anyone please give an insight into what I missed?

HTML

<form id="main-contact-form" class="contact-form" name="contact-form"       method="post" action="contactengine.php">
    <div class="col-sm-5 col-sm-offset-1">
        <div class="form-group">
            <label>Name *</label>
            <input type="text" name="Name" class="form-control" required="required">
        </div>
        <div class="form-group">
            <label>Email *</label>
            <input type="email" name="Email" class="form-control" required="required">
        </div>
        <div class="form-group">
            <label>Phone *</label>
            <input type="number" name="Phone" class="form-control">
        </div>
        <div class="form-group">
            <label>Company Name</label>
            <input type="text" class="form-control">
        </div>
    </div>
    <div class="col-sm-5">
        <div class="form-group">
            <label>Subject *</label>
            <input type="text" name="subject" class="form-control" required="required">
        </div>
        <div class="form-group">
            <label>Message *</label>
            <textarea name="message" id="Message" required="required" class="form-control" rows="8"></textarea>
        </div>
        <div class="form-group">
            <button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
        </div>
    </div>
</form>

PHP

<?php
if (isset($_POST["submit"])){   
    $EmailFrom = "$Email";   
    $EmailTo = "ben.afunsho@gmail.com";   
    $Subject = "New Message from Your Message";  
    $Name = trim(stripslashes($_POST['Name']));   
    $Phone = trim(stripslashes($_POST['Phone']));  
    $Email = trim(stripslashes($_POST['Email']));  
    $Subject = trim(stripslashes($_POST['Subject']));  
    $Message = trim(stripslashes($_POST['Message']));
    // validation    
    $validationOK = true;    
    if (!$validationOK) {      
        print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; 
        exit;
    }
    // prepare email body text    
    $Body = "You have received a new email from";    
    $Body .= "Name: ";    
    $Body .= $Name;   
    $Body .= "\n";    
    $Body .= "Phone: ";  
    $Body .= $Phone;  
    $Body .= "\n";    
    $Body .= "Email: ";    
    $Body .= $Email;    
    $Body .= "\n";    
    $Body .= "Subject: ";   
    $Body .= "$Subject: ";  
    $Body .= "\n";   
    $Body .= "Message: ";  
    $Body .= $Message;    $Body .= "\n";
    // send email     $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    // redirect to success page     
    if ($success) {        
        print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";  
    }else {     
        print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
}
?>

I only get an undefined error on the html nothing else

Rushil K. Pachchigar
  • 1,263
  • 2
  • 21
  • 40
Ben
  • 1
  • 1
  • 1
    Post the error that you get – B001ᛦ Feb 20 '17 at 09:38
  • 1
    `f ($success)` should be `if ($success)`. And you have the code that sets `$success` commented out. – Barmar Feb 20 '17 at 09:40
  • please change this line like this $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); //send email – Rushil K. Pachchigar Feb 20 '17 at 09:40
  • I think there are copying errors in the question. Now I see the `i` in `if` on the previous line. I guess the `$success =` line is really on the line after the comment. Please copy the code accurately if you want help. See http://stackoverflow.com/help/formatting – Barmar Feb 20 '17 at 09:42
  • @bub try filling out this page http://xlevelretail.com/contact-us.html – Ben Feb 20 '17 at 11:16

1 Answers1

0

There were some case sensitivity issues in your post and I corrected it and commented at corresponding lines. Check it

    <?php
    if (isset($_POST["submit"]))
     {    $EmailFrom = "$Email";   
     $EmailTo = "ben.afunsho@gmail.com";   
     $Subject = "New Message from Your Message";  
      $Name = trim(stripslashes($_POST['Name']));   
     $Phone = trim(stripslashes($_POST['Phone']));  
      $Email = trim(stripslashes($_POST['Email']));  
      $Subject = trim(stripslashes($_POST['subject']));  //s should be small
      $Message = trim(stripslashes($_POST['message'])); // m should be small
    // validation    
    $validationOK = true;    
    if (!$validationOK) {      
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";        exit;
        }
    // prepare email body text    
    $Body = "You have received a new email from";    
    $Body .= "Name: ";    
    $Body .= $Name;   
     $Body .= "\n";    
    $Body .= "Phone: ";  
      $Body .= $Phone;  
      $Body .= "\n";    
    $Body .= "Email: ";    
    $Body .= $Email;    
    $Body .= "\n";    
    $Body .= "Subject: ";   
     $Body .= $Subject; // copy paste is very bad  
      $Body .= "\n";   
     $Body .= "Message: ";  
      $Body .= $Message;    
      $Body .= "\n";

    // send email     $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    // redirect to success page     i
    if ($success) {        print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";    }
     else {        print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";    }}?>
<form id="main-contact-form" class="contact-form" name="contact-form"       method="post" action="contactengine.php">
        <div class="col-sm-5 col-sm-offset-1">
            <div class="form-group">
                <label>Name *</label>
                <input type="text" name="Name" class="form-control" required="required">
            </div>
            <div class="form-group">
                <label>Email *</label>
                <input type="email" name="Email" class="form-control" required="required">
            </div>
            <div class="form-group">
                <label>Phone *</label>
                <input type="number" name="Phone" class="form-control">
            </div>
            <div class="form-group">
                <label>Company Name</label>
                <input type="text" class="form-control">
            </div>
        </div>
        <div class="col-sm-5">
            <div class="form-group">
                <label>Subject *</label>
                <input type="text" name="subject" class="form-control" required="required">
            </div>
            <div class="form-group">
                <label>Message *</label>
                <textarea name="message" id="Message" required="required" class="form-control" rows="8"></textarea>
            </div>
            <div class="form-group">
                <input type="submit" name="submit" class="btn btn-primary btn-lg" value="Submit" />
            </div>
        </div>
    </form>
Sagar V
  • 12,158
  • 7
  • 41
  • 68