I used a Bootstrap form.
<form id="contact-form">
<div class="form-group">
<label for="inputName" >Name or company name</label>
<input type="name" class="form-control" id="inputName" aria-describedby="nameHelp" placeholder="Enter name or company name" name="name" >
</div>
<div class="form-group">
<label for="inputEmail">Email address</label>
<input type="email" class="form-control" id="inputEmail" aria-describedby="emailHelp" placeholder="Enter email" name="name">
<small id="emailHelp" class="form-text text-muted">I'll never share your email with anyone else.</small>
</div>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea name="message" class="form-control" id="inputMessage" placeholder="Type an email" value="<?= $message ?>"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
I also used Alertify
alertify.defaults.transition = "slide";
alertify.defaults.theme.submit = "btn btn-primary";
alertify.defaults.theme.cancel = "btn btn-danger";
alertify.defaults.theme.input = "form-control";
And I wanted the email to be sent using jQuery so I didn’t have to change the extension of the file to php.
(function() {
$(document).ready(function() {
return $('#contact-form').submit(function(e) {
var email, message, name;
name = document.getElementById('inputName');
email = document.getElementById('inputEmail');
message = document.getElementById('inputMessage');
if (!name.value || !email.value || !message.value) {
alertify.error('Please check your entries');
return false;
} else {
$.ajax({
method: 'POST',
url: 'sendemail.php',
data: $('#contact-form').serialize(),
datatype: 'json'
});
e.preventDefault();
$(this).get(0).reset();
return alertify.success('Message sent');
}
});
});
}).call(this);
And that’s the php file where the data is being processed.
<?php
$a=0;
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
console.log($name);
$formcontent="From: $name \n Message: $message";
$recipient = "myemail@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: index.html");
echo "Thank You!";
?>
The email isn’t being sent. What I did wrong? What I need to do next?, I deployed my page on a free hosting page called 000webhost with limited sent emails plan.
Is it because I didn’t configure something first? (Like something in the SMPT) I’ve watched several tutorial on how to do that and they use additional steps. Anyone that can guide me and tell me if what I am doing is either wrong or correct?
I am currently using a modular with that bootstrap form and also wanted to use alertify because I liked how it looks, if there is a better alternative feel free to tell me.
There are so many alternatives that I feel overwhelmed.