Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending emails automatically at the click of a button

Tags:

php

email

mailto

I am designing an Emergency Response page, and one of the features we need is to be able to click a button (e.g. 'Send details to embassy'), and then send an automatically-generated email to the intended recipient ($email_address) without having to go into Microsoft Outlook and click send. Is there a way to do this?

The only method I know is the <a href='mailto:[email protected]'> one, but this opens the email in Outlook and really I need it to be completely automated.

like image 559
Daniel H Avatar asked Apr 13 '11 13:04

Daniel H


People also ask

Can you set up Outlook to automatically send emails?

1) In the E-Mail Options dialog, select "Recurring" in the "Options" drop-down list of settings. 2) In the "Recurring" settings window, specify when you want your email to be sent every day, week or month. 3) Click OK to close the settings window and return to your inbox.

How do I send an email from a button in Salesforce?

From Setup, click the Object Manager tab. Select Cases, and open the Buttons, Links, and Actions setup page. Click New Action. For Action Type, select Send Email.


1 Answers

Something like this would work as a starting point:

<form action="" method="post">
    <input type="submit" value="Send details to embassy" />
    <input type="hidden" name="button_pressed" value="1" />
</form>

<?php

if(isset($_POST['button_pressed']))
{
    $to      = '[email protected]';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: [email protected]' . "\r\n" .
        'Reply-To: [email protected]' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);

    echo 'Email Sent.';
}

?>

UPDATE

This can be used as a Javascript function to call the mail.php page and send the email without reloading the page.

function sendemail()
{
    var url = '/mail.php';

    new Ajax.Request(url,{
            onComplete:function(transport)
            {
                var feedback = transport.responseText.evalJSON();
                if(feedback.result==0)
                    alert('There was a problem sending the email, please try again.');
            }
        });

}

You'll need Prototype for this method: http://www.prototypejs.org/api/ajax/request

I haven't tested this, but hopefully it should be along the right lines.

like image 171
gmadd Avatar answered Oct 12 '22 13:10

gmadd