Prepare email for thunderbird / Outlook /

Is it possible to prepare an email (From, To, Subject, Body, Attachments) in PHP and instead of sending it directly with PHP, open it with an email client (Thunderbird / Outlook / ...)?

My context:

  • in the form, the user selects the "To" contact and the file to send (the body is a predefined text).
  • on submit, I would like the prepared email to be displayed in his favorite mail client so that he can modify it (add CC, change body, ...)

If possible, how to do it?

+3


source to share


3 answers


Thanks everyone for your answers.

Unfortunately (and really quite unsurprisingly), it's not possible to add anchor data to a mailto (duh) link!

2 solutions:



  • If you really need to open your email client software, prepare an email with a direct link to the file in the body of the message. To do this, you need to save the file in a location accessible to the vie recipient, which is the direct link.
  • If you cannot save the file in a location accessible to the recipient (for example, your application is an intranet application behind a firewall), then the only solution is to send email through PHP directly, without using client software.
  • Or maybe you could send mail to the sender first via PHP and he sent it to the recipient himself so that he can modify the message as he sees fit. But this is a little confusing for untrained users ...

Hooray!

0


source


I would do something like this:

  • Collect information from the form
  • Process data when submitting a form
  • Present the user with a link and add variables using the schema mailto:

    .

For example, something like this in PHP:

if(isset($_POST['send_mail']))
{
    $to = $_POST['email_to'];
    $subject = $_POST['email_subject'];
    $body = 'This would be your defined body...';

    // Now prepare the URL and present it to the user:
    $url = 'mailto:'.$to.'?subject='.rawurlencode($subject).'&body='.rawurlencode($body);
    echo '<a href="'.$url.'" title="Send Email Now">Send Email</a>';

    // A boolean value to hide the form
    // Necessary logic would need to be implemented on the page for this
    $show_form = false;
}

      



Your form might look like this:

<form method="post">
    <label for="select_email_to">Recipient:</label>
    <select name="email_to" id="select_email_to">
        <option value="someone@example.com">John Doe</option>
        <option value="someone.else@example.com">Jane Doe</option>
        <otion value="a.n.other@example.com">Foo Bar</otion>
    </select>
    <label for="input_subject">Subject</label>
    <input type="text" name="subject" id="input_subject" />

    <input type="submit" name="send_mail" value="Prepare Email" />
</form>

      

If you need to include a file, I'll upload it to the server when the form is submitted, and then add a link to the uploaded file in the body of the email.

+1


source


The mailto: URL scheme shows how you can link to a new email. The browser / OS will open this letter in the mail client.

http://tools.ietf.org/html/rfc2368

0


source







All Articles