Firstly, you don't have an assigned variable called $nombre
so having error reporting set would have thrown an undefined variable warning; you may have meant to use $name
instead.
Check your Spam since you don't have a proper From:
in your header, and/or the Email is being rejected altogether due to that reason, this is a common thing nowadays.
Check that all your form elements are indeed named, this includes your submit button, since your conditional statement depends on this, and you haven't provided your HTML form.
I.e.: name="name"
and name="email"
and for the submit button name="submit"
.
It's also better to use isset()
. I.e.:
if(isset($_POST['submit'])){...}
instead of if ($_POST['submit'])
For more information on mail/headers, visit:
Example from PHP.net:
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Add error reporting to the top of your file(s) which will help find errors either.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.
For more information on mail/headers, visit:
Example from PHP.net:
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
A few things to note are:
- Is PHP installed on your server and properly configured?
- Is mail installed and properly configured?
- If running from your own computer, all of the above apply.
"it's just sending a name and an adress but it doesn't work"
- You will need to be more precise with this. "It doesn't work" doesn't define nor describe how it's not working, or any error messages you may have gotten.
If it isn't redirecting, then you may be outputting before header, another common mistake, which is something that error reporting will catch, do use it.
Here is an article on Stack about outputting before header (headers already sent), should you get that warning: