0

i recentlly uploaded my website and am having trouble getting my form to work. can someone help me out. Before I was getting an HTTP 500 error, and I realized I had a type in my code, but since I fixed it, I'm not getting any error, however Im also not receiving any emails upon submitting my form. can someone let me know what I did wrong ?!

<?php 

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $mailFrom = $_POST['mail'];
    $message = $_POST['message'];
    
    $mailTo = "info@orbitwebdesign.ca";
    $headers = "From: ".$mailFrom;
    $txt = "You have recieved an e-mail from ".$name.".\n\n".$message;
    
    mail($mailTo, $subject, $txt, $headers);
    
    header("Location: contact.php?mailsend");
} 

?>
 <section class="section-form" id="contact">
            <div class="row">
                <h2>BOOK A FREE CONSULTATION!</h2>
            </div>
            <div class="row">
                <form method="POST" action="contact.php" class="contact-form">
                    <div class="row">
                        <div class="col span-1-of-3">
                            <label for="name">Name</label>
                        </div>
                        <div class="col span-2-of-3">
                            <input type="text" name="name" id="name" placeholder="Your name" required>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col span-1-of-3">
                            <label for="mail">Email</label>
                        </div>
                        <div class="col span-2-of-3">
                            <input type="email" name="email" id="email" placeholder="Your email" required>
                        </div>
                    </div>
                
                   
                    <div class="row">
                        <div class="col span-1-of-3">
                            <label>Message</label>
                        </div>
                        <div class="col span-2-of-3">
                            <textarea name="message" placeholder="Your message"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col span-1-of-3">
                            <label>&nbsp;</label>
                        </div>
                        <div class="col span-2-of-3">
                            <input class="input-btn" name="submit" type="submit" value="Send">
                        </div>
                    </div>
                    
                </form>
                
            </div>
        </section>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Mike Z
  • 39
  • 3
  • Try as first step to ad `var_dump` to `$_POST` at the beginning of your PHP to see if he run it - this will also enable you to examine the content of the post you sent – dWinder Dec 02 '18 at 08:29
  • You didn't get errors because you're not checking for them. Enable error reporting. – Funk Forty Niner Dec 02 '18 at 14:08

2 Answers2

1

the email address is stored in $_POST['email']. but, in your contact.php, row 5:

$mailFrom = $_POST['mail'];

Try replacing $_POST['mail'] with $_POST['email']

Hope it helps.

ps Also the label in your html code is for 'mail' too instead for 'email' like the input tag

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Awesome! thanks so much. Once someone submits the form, where should it be redirecting to? back to the home page? once I tried submitting it just took me to a blank page with the extension /contact.php. should my last line in my php doc be header("Location: index.html?mailsend" – Mike Z Dec 02 '18 at 17:49
  • Yes, you sholud take back the user to the page where the submitted form was; I suggest to pass a get variable in order to display a success/error message depending if mail($mailTo, $subject, $txt, $headers) returned TRUE or FALSE. –  Dec 08 '18 at 16:38
-1

Sometimes, the mail command is locked by the provider. You can try the following to get more information:

$success = mail('example@example.com', 'My Subject', $message);
if (!$success) {
    $errorMessage = error_get_last()['message'];
}

Taken from here

Or use a dedicated class like PHPMailer or similar.

uruk
  • 1,094
  • 2
  • 14
  • 26