Is it possible to prepare an email (From, To, Subject, Body, Attachements) in PHP and, instead of directly sending it with PHP, open it with the client's email program (Thunderbird / Outlook / ...)?
My context is :
If possible, how to do that?
Thanks all for your answers.
Unfortunately (and actually quite unsurprisingly), it is not possible to put attachement data in a mailto link (duh)!
2 solutions then :
Cheers!
The mailto: URL scheme shows how you can create a link to a new email. The browser/OS will open this email in the email client.
I would do something like this:
mailto:
scheme.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'd upload it to the server when the form is submitted, and then include a link to the uploaded file in the body of the email.