Right now I am hitting my head against the wall. I simply can’t figure out what is wrong with my code! Please help me!
I’m quite new in this field, so I would love some feedback.
This is my code:
<?php
include('inc/header.php');
// Check for form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Form validation
$name = $_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ' . $name . ' <' . $email . '>';
$to = "****@***********"; // This email will receive the data of the contact.php
$subject = "New email to Brand One"; // This is the subject Brand One will receive
$body = "From: $name\
Tel: $tel\
Email: $email\
Message:\
$message"; // The actual content of the email
if ($_POST['submit']) {
if ($name != '' && $tel != '' && $email != '') {
if ($validation == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<script type="text/javascript">alert("Thank you for contacting us. We will get back to you as soon as possible.");</script>';
} else {
echo '<script type="text/javascript">alert("Something went wrong. Go back and try again!");</script>';
}
} else if ($_POST['submit'] && $validation != '4') {
echo '<script type="text/javascript">alert("You have answered the anti-spam question incorrectly!");</script>';
}
} else {
echo '<script type="text/javascript">alert("You need to fill in all required fields!");</script>';
}
}
}// End of main isset() IF.
?>
<section id="contact">
<h1 class="title">Contact Us</h1>
<h2 class="text">We'd love to hear from you.</h2>
<div class="contactform">
<form method="post" action="">
<label for="name">Name:</label>
<input id="name" name="name" type="text" placeholder="Write your name here" required aria-required="true"/>
<br/>
<label for="tel"><br/>Telephone:</label>
<input id="tel" name="tel" type="tel" placeholder="Write your number here" required aria-required="true"/>
<br/>
<label for="email"><br/>Email:</label>
<input id="email" name="email" type="email" placeholder="Write your e-mail here" required aria-required="true"/>
<br/>
<label for="validation"><br/>What is 2+2? (Anti-spam)</label>
<input id="validation" type="text" name="validation" placeholder="Type here"/>
</div>
<div class="box">
<label for="message">Message:</label>
<textarea name="message" id="message" rows="7" cols="40" placeholder="Write your message here"></textarea>
</div>
<br />
<input id="submit" name="submit" type="submit" value="Submit Message">
</form>
</div>
<div class="contactinfo">
<h3 class="undertitle">Contact Us</h3>
<p>+45 27 15 58 28</p>
<p>mail@brandone.dk</p>
<br />
<h3 class="undertitle">Visit Us</h3>
<p>Brand One</p>
<p>Museumsgade 51A,</p>
<p>7400 Herning</p>
<br />
<h3 class="undertitle">Support</h3>
<p>Mandag - Torsdag:</p>
<p>09.00 - 17.00</p>
<br />
<p>Fredag:</p>
<p>09.00 - 14.00</p>
</div>
<iframe width="700" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Museumsgade+51A,+7400+Herning&aq=&sll=56.132621,8.975269&sspn=0.007318,0.01929&t=m&g=Museumsgade+51A,+7400+Herning&ie=UTF8&hq=&hnear=Museumsgade+51A,+7400+Herning,+Denmark&ll=56.132621,8.975269&spn=0.00183,0.004823&z=14&output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=q&source=embed&hl=en&geocode=&q=Museumsgade+51A,+7400+Herning&aq=&sll=56.132621,8.975269&sspn=0.007318,0.01929&t=m&g=Museumsgade+51A,+7400+Herning&ie=UTF8&hq=&hnear=Museumsgade+51A,+7400+Herning,+Denmark&ll=56.132621,8.975269&spn=0.00183,0.004823&z=14" style="color:#0000FF;text-align:left"></a></small>
<div class="solutionslink">
<a href="solutions.php"><h1 class="title">What can we do for you?</h1></a>
</div>
</section> <!-- end of contact -->
<?php
include('inc/footer.php');
?>