Im creating page with parallax scrolling, contact box is in last section. If I use simple html + php contact box, page will refresh to first section, so user will have to scroll back to contact section to see result. To correct this I am trying to make script that will send email without reloading page. (by Jquery)
This is how it looks like:
HTML:
<form method="post" enctype="multipart/form-data" id="formularz">
<label for="name">Imię</label><input type="text" name="name" id="formularz_name"/></br></br>
<label for="email">Email</label><input type="text" name="email" id="formularz_email"/></br></br>
<label for="phone">Telefon</label><input type="text" name="phone" id="formularz_phone"/></br></br>
<label for="enquiry">Zapytanie</label><textarea name="enquiry" cols="20" rows="10" id="formularz_text"></textarea></br></br>
<input type="submit" id="contact_button" value="Wyślij" />
</form>
Jquery:
$('#contact_button').click(function () {
var name = $('#formularz_name').val();
var email = $('#formularz_email').val();
var phone = $('#formularz_phone').val();
var text = $('#formularz_text').val();
$.ajax({
url: 'inc/contact.php',
data: {'name': name, 'email': email, 'phone': phone, 'text': text},
type: 'POST',
success: function(odp){
alert(odp);
}
});
});
PHP:
<?php
if (!$name || !$email || !$phone || !$text) {
$problem = TRUE;
echo("<br><p>Musisz wypełnić wszystkie pola.</p>");
}
if (!$problem){
$data = date("d.m.y");
$message = "
<p>Name: $name</p>
<p>Phone: $phone</p>
<p>Email: $email</p>
<br>
<p>Enquiry: $text</p>";
$od = "$email";
$content = $message;
$header = "From: $od \r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
(mail('lethysek@gmail.com', 'New message from website Angelzena', $content, $header));
echo("<br><p>Wiadomość została wysłana.</p>");
}else{
echo("<p>Spróbuj ponownie</p>");
}
?>
Why it doesn't work? When i click submit, page is refreshed and nothing happens.