-1

I've been scouring the countless other php contact form questions for the past five hours and can't for the life of me figure out why mine isn't working. I'm a total newbie to PHP other than some 'lessons' from Codecademy. So - here's what we've got. Single page HTML file. Here's the form:

<div id="contact-form-section">
                        <div class="status alert alert-success" style="display: none"></div>
                        <form id="contact-form" class="contact" name="contact-form" method="post" action="send-mail.php">
                            <div class="form-group">
                                <input type="text" name="name" class="form-control name-field" required="required" placeholder="Your Name"></div>
                                
                                <div class="form-group">
                                    <input type="email" name="email" class="form-control mail-field" required="required" placeholder="Your Email">
                                </div> 
                                
                                <div class="form-group">
                                <input type="text" name="tel" class="form-control" required="required" placeholder="Your Phone Number">
                                </div>
                                       
                                <div class="form-group">
                                    <textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
                                </div> 
                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary">Send</button>
                                </div>
                            </form> 
                        </div>

And here's the php, with the email I wanted to send to replaced by example@example.com. Trying to figure out from some other tutorials mopped together to figure out how it works. Wanted to have the submit button fire the alert, then go back to the index page.

<?

$name=$_POST['name'];
$Email=$_POST['email'];
$tel=$_POST['tel']
$website=$_POST['url'];
$message=$_POST['message'];


    
    $body .= "Name: " . $name . "\n"; 
    $body .= "Email: " . $Email . "\n"; 
    $body .= "Telephone: " . $tel . "\n";
    $body .= "Website: " . $website . "\n"; 
    $body .= "Message: " . $message . "\n"; 

    //Receiving email
    mail("example@example.com","New email",$body); 

  
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>alert("Your message has been sent successfully. We will contact you shortly.");</script>
<meta HTTP-EQUIV="REFRESH" content="0; url=index.html"> 

</head>

What am I doing wrong here? Whenever I click on the submit button, it brings my to my send-mail.php page, but no notification comes up, and the email doesn't send. Any help is greatly appreciated, I know these questions come up far too often on Stack - like I said, I spent five hours sifting through contact form questions trying to figure out what I screwed up on here.

IkeDoud
  • 77
  • 2
  • 13

1 Answers1

2

missing a semi colon at the end of this line - it should read:

$tel=$_POST['tel'];

also are you actually declaring the <?php at the top of the php page. At the moment you have <? and it should be

<?php
gavgrif
  • 15,194
  • 2
  • 25
  • 27
  • *"At the moment you have and it should be – Funk Forty Niner Feb 29 '16 at 23:01
  • 2
    The other problem is that $body .= "Name: " . $name . "\n"; should be $body = "Name: " . $name . "\n"; The first equal sign should NOT have a dot in front of it. – Kobbe Feb 29 '16 at 23:04
  • @Fred cos its good practise - as stated here:(php.net/manual/en/language.basic-syntax.phptags.php) - PHP also allows for short open tag (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option). – gavgrif Feb 29 '16 at 23:05
  • Thank you so much gavgrif and Kobbe, I really appreciate it, just saved a ton of frustration for me. I guess this is a sign I need to use an IDE instead of a text editor. >.< Again, I appreciate it. – IkeDoud Feb 29 '16 at 23:12
  • @IkeDoud its a sign you should turn error reporting and display on –  Feb 29 '16 at 23:22