Hola, puedes intentar lo siguiente:
Primero añade a tu formulario un checkbox con el nombre de "remail" o con cualquier otro, de esta forma: <input type="checkbox" name="remail">
Segundo, edita tu codigo php para que quede asi:
Código PHP:
<?php
error_reporting(E_NOTICE);
function valid_email($str)
{
return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}
if ($_POST['nombres']!='' && $_POST['empresa']!='' && $_POST['telefono']!='' && $_POST['email']!='' && valid_email($_POST['email']) && strlen($_POST['message'])>10)
{
$to = '[email protected]';
$headers = 'From: '.$_POST['email'].''. "\r\n" .
'Reply-To: '.$_POST['email'].'' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject = "Consulta";
$message =
"Mensaje:" . " " . htmlspecialchars($_POST['message'])
. "\r\n" . "Nombre y apellido:" . " " . htmlspecialchars($_POST['nombres'])
. "\r\n" . "Direccion:" . " " . htmlspecialchars($_POST['empresa'])
. "\r\n" . "Codigo postal:" . " " . htmlspecialchars($_POST['telefono'])
. "\r\n" . "E-mail:" . " " . htmlspecialchars($_POST['email'] );
if (mail($to, $subject, $message, $headers))
{
if (isset($_POST['remail']))
{
if (mail($_POST['email'],$subject,$message,$headers))
{
echo '<p style="color:green;">Gracias '.$_POST['nombres'].'. Su consulta fue enviada.</p>';
}
else {
echo "<p>Message not sent. Please make sure you're not
running this on localhost and also that you
are allowed to run mail() function from your webserver</p>";
}
}
else
{
echo '<p style="color:green;">Gracias '.$_POST['nombres'].'. Su consulta fue enviada.</p>';
}
}
else {
echo "<p>Message not sent. Please make sure you're not
running this on localhost and also that you
are allowed to run mail() function from your webserver</p>";
}
}
else {
echo '<p style="color:red;">Por favor, asegúrese de que completó todos los campos requeridos y que ingresó un email válido.</p>';
}
?>
Recuerda, si cambias el nombre al checkbox de "remail" a otro, tambien hazlo en el codigo php donde dice $_POST['remail'].
Saludos, espero que te funcione ;)