1

I am writing a php application which (amongst other things) creates some reports for emailing. I want to enable my customer to click on a "create emails" button which will cause a number of email client windows to open pre filled with data, so that my customer can check the content before sending the emails.

I could generate an html page with a number of mailto tags on, which the customer then clicks on to open the emails (for checking) before sending, but this is obviously labour intensive and part of the reason I'm writing this php application. Is the solution to have some javascript on the generated html page which fires all the mailto links on page load? Or is there a better way?

ADDITIONAL EDIT: The key point is that the customer needs to manually check the content before the emails are sent - sorry I have not been clear. The customer has since specified that he wants the emails to appear as draft pre-composed emails in his email client rather than appearing on a web page.

Thanks

rbassett
  • 383
  • 3
  • 17
  • I would not rely on `mailto` links to send mail from your application. – jeroen Jul 11 '14 at 16:03
  • @jeroen - What reasons are there for not relying on mailto? I am aware that someone could not have their mail client configured but this application is for a specific customer who I know do have their email clients configured correctly. – rbassett Jul 11 '14 at 16:58

3 Answers3

2

It would be much more versatile and effective to send the mail on the server side, rather than asking the client to rely on their own mail client (when someone clicks a mailto link in the browser, the browser attempts to open a mail client like Outlook or Thunderbird, which may or may not be configured). You can print various forms on the page which include subject, to address and message inputs, ingest them via post (i.e. the user submits the form), and then send the emails from the server directly in response to the form submission. Start with this:

http://us3.php.net/manual/en/function.mail.php

And check out PHPMailer:

https://github.com/PHPMailer/PHPMailer

Also if you're working with a framework, they've likely got their own utilities for sending mail, which is preferable to the above 2 approaches. A very simple example of what I'm talking about might look something like this:

<form action='/' method='post'>
  To Address: <input type='text' name='to_addr' /> <br/>
  Subject: <input type='text' name='subject' /> <br/>
  Message: <textarea name='to_addr'></textarea> <br/><br/>
  <input type='submit' name='send' value='Send Message' />
</form>
<?php

if(!empty($_POST['send']))
  mail( $_POST['to_addr'] , $_POST['subject'] , $_POST['message'] , 'From: no-reply@somedomain.com');
oliakaoil
  • 1,615
  • 2
  • 15
  • 36
  • Interesting idea - thanks. Unfortunately I have checked with my customer and they don't "trust" this mechanism of seeing the email inside a webpage - they want to see an email in their email client (as if they had composed the email themselves), before they click on the send button. – rbassett Jul 11 '14 at 16:57
  • Unfortunately I don't think there is a programatic way to send e-mail on the client side, especially from a separate program like an e-mail client, so your client will have to click send for each and every e-mail if they want to use their own client-side e-mail client (http://www.hark.com/clips/qtmrlmfjks-youre-one-groovy-baby-baby-too-many-babies). So you're not going to be saving them much by opening those windows programatically in any case? – oliakaoil Jul 11 '14 at 17:02
  • Thanks for your comments. The time being saved is in the creating of the reports and opening 50 odd pre composed draft emails containing the reports (each different) which can then be checked by the customer before they click on send on each one. They don't trust the application to create the reports correctly so want to do all the checking manually. Think I'm stuck with programmatically clicking on 50 mailto: links. – rbassett Jul 12 '14 at 08:38
0

You can use this piece of code.

    $subject = 'Your mail subject';
    $message = 'Your message.';
    $header  = "From: webmaster@yourwebsite.com"."\r\n";
    $header .= "Reply-To: webmaster@yourwebsite.com"."\r\n";
    $header .= "MIME-Version: 1.0"."\r\n";
    $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
    $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
    $header .= "X-Mailer: PHP v".phpversion();
    mail($newemail, $subject, $message, $header);
    header('Location: '.$success_page);
    exit;
Ayan
  • 2,738
  • 3
  • 35
  • 76
  • Unfortunately this just sends an email, which is not what is required. The customer needs to read / check (and modify) the emails that are created, before the customer then clicks on send. – rbassett Jul 11 '14 at 16:53
  • You can fetch the data from a database and then prefill the fields with that data(PREVIEWING) which then can be sent with the piece of code above. Hope this helps. – Ayan Jul 11 '14 at 17:39
  • Thanks but the key is that no sending should occur. The customer will do the sending manually, I am just to compose the emails. – rbassett Jul 12 '14 at 08:48
0

After further investigation, it appears I can't use mailto html tag, as it will not accept html tags within the a href (eg no formatted tables) and is restricted in the number of characters.

So the solution for now is to return to use a php mail form as suggested above, with a cc to the customers mail account so they can store a copy of the email in their email account as they have requested. Also I shall be using tinymce so that the customer can edit the pre-composed html within the email body.

Community
  • 1
  • 1
rbassett
  • 383
  • 3
  • 17