boo@foo.a if (filter_var($campo, FILTER_VALIDATE_EMAIL)) { $emailSeparadoExtension = explode('.', $campo); if (count($emailSeparadoExtension) === 2 && strlen($emailSeparadoExtension[1]) < 2) { return false; } } // Otros return filter_var($campo, FILTER_VALIDATE_EMAIL); } /** * Valida que $texto no supere $limite * @param string $texto * @param int $limite * @return bool */ function validarLetrasMaximas(string $texto, int $limite): bool { return strlen(trim($texto)) <= $limite; } //====================================================================== // INICIO //====================================================================== // Envia el correo si al informacion es correcta if ($validado) { // Generamos las plantillas $loader = new \Twig\Loader\FilesystemLoader('templates'); $twig = new \Twig\Environment($loader); $variablesEmail = [ 'nombre' => $nombre, 'email' => $email, 'mensaje' => $mensaje ]; $plantillaPlana = $twig->render('contacto.txt', $variablesEmail); $plantillaHTML = $twig->render('contacto.html', $variablesEmail); // Enviamos email $emailSendGrid = new \SendGrid\Mail\Mail(); $emailSendGrid->setFrom("andros@fenollosa.email", "Web"); $emailSendGrid->setSubject("Contacto desde mi web"); $emailSendGrid->addTo("andros@fenollosa.email", "Yo"); $emailSendGrid->addContent("text/plain", $plantillaPlana); $emailSendGrid->addContent( "text/html", $plantillaHTML); $sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY')); try { $response = $sendgrid->send($emailSendGrid); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage() . "\n"; } }