I am new to these platforms, I already have the code in HTML and PHP, however when sending a message from the page that has already been uploaded to a server, the email that I enter in PHP does not arrive, I would like to know what part of the code makes me lack.
HTML code:
<form action="contact_me" method="post" name="sentMessage" id="contactForm" >
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" id="name" class="form-control" placeholder="Nombre" required="required">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input type="email" id="email" class="form-control" placeholder="Correo" required="required">
<p class="help-block text-danger"></p>
</div>
</div>
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Mensaje" required></textarea>
<p class="help-block text-danger"></p>
</div>
<div id="success"></div>
<button type="submit" class="btn btn-default">Enviar</button>
</form>
PHP code:
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$to = '[email protected]'; /
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Thanks.
You are missing several things:
1. In the HTML
You should know that the tag they use
$_POST, $_GET, $_REQUEST
and other relatives is thename
HTML element tag. That means that if you submit the form and then do$nombre=$_POST['name'];
, what PHP will do is search the form data for the one with thename='name'
. It won't find it, because you're using the tagid
in the HTML elements.You can use both tags, or you can change the tag
id
toname
, as you prefer. Butname
you can not miss in this case.For example:
Or, if you want to keep the tag
id
:2. In PHP
Simply apply the practices taught in the PHP Manual, when it explains the function
mail
:When you send the mail, where is $headers? Also, in the form, you should put in each field a value with the php variable that it collects, to send it when pressing the Submit button, for example:
Hope this can help you.