dimanche 8 octobre 2017

mail function doesn't work with condition

i have a contact form in my site that sends mails using the php's mail function.

This is my code:

    <?php
if(isset($_POST['your-email'])) {


$email_to = "felipepinoredes@gmail.com";
$email_subject = "Contacto Codelco";




$email_message = "Detalles del formulario de contacto:\n\n";
$email_message .= "Nombre: " . $_POST['your-name'] . "\n";
$email_message .= "E-mail: " . $_POST['your-email'] . "\n";
$email_message .= "Comentarios: " . $_POST['your-message'] . "\n\n";



$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

echo "¡El formulario se ha enviado con éxito!";
}
?>

If i leave it just like that, it won't send the email, but, if i delete the if and leave it like this, it works:

$email_to = "felipepinoredes@gmail.com";
$email_subject = "Contacto Codelco";

// Aquí se deberían validar los datos ingresados por el usuario


$email_message = "Detalles del formulario de contacto:\n\n";
$email_message .= "Nombre: " . $_POST['your-name'] . "\n";
$email_message .= "E-mail: " . $_POST['your-email'] . "\n";
$email_message .= "Comentarios: " . $_POST['your-message'] . "\n\n";


// Ahora se envía el e-mail usando la función mail() de PHP
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);

echo "¡El formulario se ha enviado con éxito!";

But i need the condition, i don't want blank mails sent automatically everytime i load the page.

Help, please.

Aucun commentaire:

Enregistrer un commentaire