Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////
- // front.js ///
- ////////////////////////////////
- function contactForm() {
- $("#contact-form").submit(function () {
- var url = "contact.php"; // the script where you handle the form input.
- $.ajax({
- type: "POST",
- url: url,
- data: $(this).serialize(), // serializes the form's elements.
- success: function (data)
- {
- var messageAlert = 'alert-' + data.type;
- var messageText = data;
- var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable animated bounceIn"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + messageText + '</div>';
- if (messageAlert!=0 && messageText!=0) {
- $('#contact-form').find('.messages').html(alertBox);
- }
- }
- });
- return false; // avoid to execute the actual submit of the form.
- });
- }
- ////////////////////////////////
- // contact.php ///
- ////////////////////////////////
- <?php
- /**
- * configure here
- */
- $from = $_POST['email'];
- $to = 'Szymon_Piszczatowski <piszczatowskiszymon@gmail.com>';
- $subject = 'Nowa wiadomość z portfolio';
- $fields = array('name' => 'Imie', 'surname' => 'Nazwisko', 'phone' => 'Telefon', 'email' => 'Email', 'message' => 'Wiadomość');
- $htmlHeader = '';
- $htmlFooter = '';
- $okMessage = 'Contact form succesfully submitted. Thank you, I will get back to you soon!';
- $htmlContent = '<h1>New message from contact form</h1>';
- /* DO NOT EDIT BELOW */
- /* use classes */
- $htmlContent .= '<table>';
- foreach ($_POST as $key => $value) {
- if (isset($fields[$key])) {
- $htmlContent .= "<tr><th>$fields[$key]</th><td>$value</td></tr>";
- }
- }
- $htmlContent .= '</table>';
- /* compose html body */
- $htmlBody = $htmlHeader . $htmlContent . $htmlFooter;
- $headers[] = 'MIME-Version: 1.0';
- $headers[] = 'Content-type: text/html; charset=iso-8859-1';
- $headers[] = 'To: Szymon Piszczatowski <piszczatowskiszymon@gmail.com>';
- $headers[] = 'From: piszczatowskiszymon.pl <piszczatowskiszymon@gmail.com>';
- if(mail($to, $subject, $htmlBody, implode("\r\n", $headers))){
- echo( $okMessage);
- }else {
- header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized', true, 401);
- die('401 Unauthorized');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement