Me gustaría poder enviar un correo electrónico ingresando una URL como
example.com/api/send-email?email=bob@example.org&name=Robert&template=job2231
luego se envía un correo electrónico basado en una plantilla preconfigurada que toma los email
parámetros name
.
Habría iniciado sesión en example.com a través de su interfaz de usuario web, por lo que, idealmente, la autenticación se maneja en segundo plano, antes de enviar el correo electrónico. Por supuesto, si no ha iniciado sesión, el correo electrónico no se envía.
¿Tiene alguna recomendación para example.com o un producto equivalente? Puede ser alojado o autohospedado.
Solución de alojamiento propio (económica y configurable, pero usted asume los riesgos y responsabilidades de protegerla):
Cree un solo archivo index.php y alójelo en un servidor PHP
<?php
if(isset($_POST['submit'])){
$to = $_POST['email'];
$from = "mailer@yourcompany.com";
$name = $_POST['name'];
$subject = "Sample Subject";
$message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
// If you want to have a success page, uncomment the next line
// header('Location: thank_you.php');
// to redirect to another page.
// you need to create another file named thank_you.php
}
?>
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>
<form action="" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
EDITAR: para la autenticación, puede hacer algo simple usando la autenticación HTTP (no es súper seguro ni nada, pero simplemente hace el trabajo)
<?php
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
);
if ($is_not_authenticated) {
header('HTTP/1.1 401 Authorization Required');
header('WWW-Authenticate: Basic realm="Access denied"');
exit;
} else {
// all that code from above goes here...
}
?>
andres corredor