I'd like to be able to send an email by entering a URL like

example.com/api/[email protected]&name=Robert&template=job2231 

then an email is sent based on a pre-configured template that takes in the email, name parameters.

I would have logged into example.com via their web UI, so ideally authentication is handled in the background - wrt to sending the email. Of course if not logged in, the email isn't sent.

Do you have any recommendations for example.com or an equivalent product? Can be hosted or self-hosted.

  • This should be a comment, but I don't have enough reputation. Would this be a regular link and the email would be sent as soon as the user opens it in the browser? In this case users might send it too often by accident. Sometimes when they visit it by themselves, sometimes when browsers sync automatically. There was a story of a developer who added garage door automation via a link and this happened to him: twitter.com/rombulow/status/990684453734203392 . One workaround would be asking the user to press a button to confirm sending the email. Is this acceptable? Commented Jun 13, 2018 at 12:07

1 Answer 1


Self hosting solution (cheap and configurable, but you take up the risks and responsibilities of securing it):

Create a single index.php file and host it on a PHP server

    $to = $_POST['email'];
    $from = "[email protected]";
    $name = $_POST['name'];
    $subject = "Sample Subject";
    $message = $name . " " . " wrote the following:" . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;

    // 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>
<title>Form submission</title>

<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">


EDIT: For authentication, you can do something simple using HTTP auth (It's not super secure or anything, but it just does the job)

    $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"');
    } else {
        // all that code from above goes here...
  • Note: The asker also wants authentication, it is easy with a server like Apache but you might want to add a paragraph about that :-)
    – Nicolas Raoul
    Commented Jun 18, 2018 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.