Terabyte
Terabyte

Reputation: 69

Javascript - Mail

I want to send an email in a text-area to many other users. In the text-area, named content, if I typed "user" surrounded by stars, I want to have them filled in with each email's username (the text before the "@"). That would yield many different with each username in each email. Then when I hit a button, I want to have all the emails sent to each corresponding user. This is my mail function so far:

function mail(){
    var options = document.getElementById('users').options
    var emails = []
    for(var i = 2; i < options.length; i++){
        emails.push(options[i].innerHTML)
    }   
}

How do I do this? Thanks!!!

Upvotes: 1

Views: 78

Answers (1)

Jack Bashford
Jack Bashford

Reputation: 44107

Unfortunately it's not possible to send an email using JavaScript, but you can do it with PHP. Here, the variable options you have above has been placed in a form and sent to the PHP page via POST, with the name="options" in the input attribute:

<?php
    $options = $_POST['options'];
    $to = "[email protected]";
    $subject = "Random Life";
    $body = "Lorem ipsum dolor. $options";

    mail ($to,$subject,$body);

 ?>

This will send an email to [email protected], with the subject Random Life, and the content Lorem ipsum dolor [options], where options is the value passed by the form.

But in finality, no, it is not possible to send an email using JavaScript currently. It may be possible in future years, but currently not available.

Upvotes: 1

Related Questions