Estoy haciendo un sitio de prueba y necesito generar el php del formulario contacto. lo que tengo armado es lo siguiente.
<?php
// Email address verification
function isEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if($_POST) {
// Enter the email where you want to receive the message
$emailTo = '[email protected]';
$clientEmail = addslashes(trim($_POST['email']));
$subject = addslashes(trim($_POST['subject']));
$empresa = addslashes(trim($_POST['empresa']));
$telefono = addslashes(trim($_POST['telefono']));
$message = addslashes(trim($_POST['message']));
$array = array('emailMessage' => '', 'telefonoMessage' => '', 'empresaMessage' => '', 'subjectMessage' => '', 'messageMessage' => '');
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Invalid email!';
}
if(!isEmail($empresa)) {
$array['empresaMessage'] = 'Invalid email!';
}
if(!isEmail($telefono)) {
$array['telefonoMessage'] = 'Invalid email!';
}
if($subject == '') {
$array['subjectMessage'] = 'Empty subject!';
}
if($message == '') {
$array['messageMessage'] = 'Empty message!';
}
if(isEmail($clientEmail) && $subject != '' && $message != '') {
// Send email
$headers = "From: " . $clientEmail . " <" . $clientEmail . ">" . "\r\n" . "Reply-To: " . $clientEmail;
mail($emailTo, $subject . " (bootstrap contact form)", $message, $headers);
}
echo json_encode($array);
}
?>
<form role="form" action="contacto.php" method="post">
<input maxlength="100" required="required" class="form-control" placeholder="Nombre" type="text" name="subject" />
<input maxlength="100" type="text" required="required" class="form-control" placeholder="Empresa" type="text" name="empresa" />
<input maxlength="100" required="required" class="form-control" type="text" name="email" placeholder="Email" id="contact-email"/>
<input maxlength="100" type="phone" required="required" class="form-control" placeholder="Teléfono" name="telefono"/>
<textarea class="form-control" name="message" rows="4" placeholder="Dejanos tu consulta..." ></textarea>
<input class="btn" type="submit" name="">
</form>
El problema es que lo probé y me salta un mensaje que dice;
{"emailMessage":"","telefonoMessage":"Invalid email!","empresaMessage":"Invalid email!","subjectMessage":"","messageMessage":""}