Skip to content

Instantly share code, notes, and snippets.

@poszlo
Created October 27, 2015 08:56
Show Gist options
  • Save poszlo/8ca7032296a1f26b8ada to your computer and use it in GitHub Desktop.
Save poszlo/8ca7032296a1f26b8ada to your computer and use it in GitHub Desktop.
Send Form (HTML+PHP+Sweet Alert)
<?php
$to = 'your@email.com' . "\r\n";
$subject = 'Subject';
$name = $_POST['nombre'];
$email = $_POST['email'];
$message = "************************************************** \r\n" .
"Message from you website! \r\n" .
"************************************************** \r\n" .
"Name: " . $name . "\r\n" .
"E-mail: " . $email . "\r\n" .
"Message: " . $_POST["message"] . "\r\n";
$headers = "From: " . $name . "<" . $email . "> \r\n" .
"Reply-To: " . $email . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
"Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to, $subject, $message, $headers);
?>
<form role="form" id="contact-form" method="post">
<label for="name">Name</label>
<input type="text" placeholder="Full Name" name="name" required>
<label for="email">Email</label>
<input type="email" placeholder="Your Email" name="email" required>
<label>Message</label>
<textarea name="message" placeholder="Your Message" rows="9"></textarea>
<button type="submit" class="btn">Send</button>
</form>
$(document).ready(function(){
$('#contact-form').on('submit',function(e) { //Don't foget to change the id form
$.ajax({
url:'contact.php', //===PHP file name====
data:$(this).serialize(),
type:'POST',
success:function(data){
console.log(data);
//Success Message == 'Title', 'Message body', Last one leave as it is
swal("¡Success!", "Message sent!", "success");
},
error:function(data){
//Error Message == 'Title', 'Message body', Last one leave as it is
swal("Oops...", "Something went wrong :(", "error");
}
});
e.preventDefault(); //This is to Avoid Page Refresh and Fire the Event "Click"
});
});
@tunjicodeit
Copy link

prashanp16 - do the following

-Check your input field name
-Check make sure you import all the sweet alert library
Thats all

@Amitpwa
Copy link

Amitpwa commented Apr 3, 2022

you need to give from emails also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment