Solved

Insert Table into email from HTML

Posted on 2014-01-10
8
968 Views
Last Modified: 2016-01-07
I have created the HTML code for my website and I cannot figure out how to get the appropriate table to automatically populate in the email via the mail to function. I am wondering if someone can help me out...

POC Tool template should be included in the email to STI-AS-CALOGUE-MANAGE

MRM template should be included in the email to STI-AS-CALOGUE-MANAGE

PCO Tool Access template should be included in the email to STI-AS-CALOGUE-MANAGE

I am looking to get a mail to function next to the name of each template that will include the appropriate template

Please Help me!?!?



<table>
  <tr>
    <td>col 1</td>
    <td>col 2</td>
  </tr>
  <tr>
    <td>col 1</td>
    <td>col 2</td>
  </tr>
</table>
   

Open in new window

0
Comment
Question by:jim__allen
  • 3
  • 3
8 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 39772941
Hello jim__allen,

Look at following link to see how you can add subject and body to mailto

http://neworganizing.com/content/blog/tip-prepopulate-mailto-links-with-subject-body-text

simple example can be done as following,

<A HREF="mailto:you@yourdomain.com?subject=Your Subject&body=Message for the body">you@yourdomain.com</a>

This method is not recommended as it might not work in all browsers or might result differently for different mail clients set by user.

Looking at your code it seems you want html table to be included in your mailto body.

For that, I recommend to use some server side scripting language and special email form or page which your user can fill and email.

Hope this will help you.

Thank you.

Amar Bardoliwala
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39772949
jim__allen,

Consider sending a post to via a 3rd party smtp service.  You can use mandrill and get 11,000 free per month.  

http://mandrill.com/

You can have your choice of api's https://mandrillapp.com/docs/integrations.html 
If you post your form to a php page
<?php

require_once 'Mandrill/Templates.php';
require_once 'Mandrill/Exports.php';
require_once 'Mandrill/Users.php';
require_once 'Mandrill/Rejects.php';
require_once 'Mandrill/Inbound.php';
require_once 'Mandrill/Tags.php';
require_once 'Mandrill/Messages.php';
require_once 'Mandrill/Whitelists.php';
require_once 'Mandrill/Ips.php';
require_once 'Mandrill/Internal.php';
require_once 'Mandrill/Subaccounts.php';
require_once 'Mandrill/Urls.php';
require_once 'Mandrill/Webhooks.php';
require_once 'Mandrill/Senders.php';
require_once 'Mandrill/Exceptions.php';

class Mandrill {
    
    public $apikey;
    public $ch;
    public $root = 'https://mandrillapp.com/api/1.0';
    public $debug = false;

    public static $error_map = array(
        "ValidationError" => "Mandrill_ValidationError",
        "Invalid_Key" => "Mandrill_Invalid_Key",
        "PaymentRequired" => "Mandrill_PaymentRequired",
        "Unknown_Subaccount" => "Mandrill_Unknown_Subaccount",
        "Unknown_Template" => "Mandrill_Unknown_Template",
        "ServiceUnavailable" => "Mandrill_ServiceUnavailable",
        "Unknown_Message" => "Mandrill_Unknown_Message",
        "Invalid_Tag_Name" => "Mandrill_Invalid_Tag_Name",
        "Invalid_Reject" => "Mandrill_Invalid_Reject",
        "Unknown_Sender" => "Mandrill_Unknown_Sender",
        "Unknown_Url" => "Mandrill_Unknown_Url",
        "Unknown_TrackingDomain" => "Mandrill_Unknown_TrackingDomain",
        "Invalid_Template" => "Mandrill_Invalid_Template",
        "Unknown_Webhook" => "Mandrill_Unknown_Webhook",
        "Unknown_InboundDomain" => "Mandrill_Unknown_InboundDomain",
        "Unknown_InboundRoute" => "Mandrill_Unknown_InboundRoute",
        "Unknown_Export" => "Mandrill_Unknown_Export",
        "IP_ProvisionLimit" => "Mandrill_IP_ProvisionLimit",
        "Unknown_Pool" => "Mandrill_Unknown_Pool",
        "Unknown_IP" => "Mandrill_Unknown_IP",
        "Invalid_EmptyDefaultPool" => "Mandrill_Invalid_EmptyDefaultPool",
        "Invalid_DeleteDefaultPool" => "Mandrill_Invalid_DeleteDefaultPool",
        "Invalid_DeleteNonEmptyPool" => "Mandrill_Invalid_DeleteNonEmptyPool"
    );

    public function __construct($apikey=null) {
        if(!$apikey) $apikey = getenv('MANDRILL_APIKEY');
        if(!$apikey) $apikey = $this->readConfigs();
        if(!$apikey) throw new Mandrill_Error('You must provide a Mandrill API key');
        $this->apikey = $apikey;

        $this->ch = curl_init();
        curl_setopt($this->ch, CURLOPT_USERAGENT, 'Mandrill-PHP/1.0.50');
        curl_setopt($this->ch, CURLOPT_POST, true);
        curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($this->ch, CURLOPT_HEADER, false);
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 30);
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 600);

        $this->root = rtrim($this->root, '/') . '/';

        $this->templates = new Mandrill_Templates($this);
        $this->exports = new Mandrill_Exports($this);
        $this->users = new Mandrill_Users($this);
        $this->rejects = new Mandrill_Rejects($this);
        $this->inbound = new Mandrill_Inbound($this);
        $this->tags = new Mandrill_Tags($this);
        $this->messages = new Mandrill_Messages($this);
        $this->whitelists = new Mandrill_Whitelists($this);
        $this->ips = new Mandrill_Ips($this);
        $this->internal = new Mandrill_Internal($this);
        $this->subaccounts = new Mandrill_Subaccounts($this);
        $this->urls = new Mandrill_Urls($this);
        $this->webhooks = new Mandrill_Webhooks($this);
        $this->senders = new Mandrill_Senders($this);
    }

    public function __destruct() {
        curl_close($this->ch);
    }

    public function call($url, $params) {
        $params['key'] = $this->apikey;
        $params = json_encode($params);
        $ch = $this->ch;

        curl_setopt($ch, CURLOPT_URL, $this->root . $url . '.json');
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
        curl_setopt($ch, CURLOPT_VERBOSE, $this->debug);

        $start = microtime(true);
        $this->log('Call to ' . $this->root . $url . '.json: ' . $params);
        if($this->debug) {
            $curl_buffer = fopen('php://memory', 'w+');
            curl_setopt($ch, CURLOPT_STDERR, $curl_buffer);
        }

        $response_body = curl_exec($ch);
        $info = curl_getinfo($ch);
        $time = microtime(true) - $start;
        if($this->debug) {
            rewind($curl_buffer);
            $this->log(stream_get_contents($curl_buffer));
            fclose($curl_buffer);
        }
        $this->log('Completed in ' . number_format($time * 1000, 2) . 'ms');
        $this->log('Got response: ' . $response_body);

        if(curl_error($ch)) {
            throw new Mandrill_HttpError("API call to $url failed: " . curl_error($ch));
        }
        $result = json_decode($response_body, true);
        if($result === null) throw new Mandrill_Error('We were unable to decode the JSON response from the Mandrill API: ' . $response_body);
        
        if(floor($info['http_code'] / 100) >= 4) {
            throw $this->castError($result);
        }

        return $result;
    }

    public function readConfigs() {
        $paths = array('~/.mandrill.key', '/etc/mandrill.key');
        foreach($paths as $path) {
            if(file_exists($path)) {
                $apikey = trim(file_get_contents($path));
                if($apikey) return $apikey;
            }
        }
        return false;
    }

    public function castError($result) {
        if($result['status'] !== 'error' || !$result['name']) throw new Mandrill_Error('We received an unexpected error: ' . json_encode($result));

        $class = (isset(self::$error_map[$result['name']])) ? self::$error_map[$result['name']] : 'Mandrill_Error';
        return new $class($result['message'], $result['code']);
    }

    public function log($msg) {
        if($this->debug) error_log($msg);
    }
}

Open in new window


Or using smtp http://help.mandrill.com/categories/20090941-SMTP-Integration  again in php this version could be easier
<?php
require 'class.phpmailer.php';

$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com';                 // Specify main and backup server
$mail->Port = 587;                                    // Set the SMTP port
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME';                // SMTP username
$mail->Password = 'MANDRILL_APIKEY';                  // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress('josh@example.net', 'Josh Adams');  // Add a recipient
$mail->AddAddress('ellen@example.com');               // Name is optional

$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <strong>in bold!</strong>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

Open in new window


With either of these, methods, you will need to sign up with mandrill.com and get yourself a username, pass and api key.  This will be a lot more effective and user friendly then using the method your are trying to go for.  

Fyi, you could very easily do this all in php and not go through a 3rd party smtp service and send mail via your server.  The problem with doing this is your mail is detected as sending via your server and likely to be marked as spam.  When you do this, make sure you use a captcha or some device to prevent people from sending over and over.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39773161
As Amar said you are relying on the client to send the email via their default email client. A very unreliable method.  Amar has also said to use a server side script.  Then the email comes from you and your website.  Gives you a lot more control over not only sending the email but also how it looks.

For feedback or inquiries, I would use the server side method.  For marketing etc I would use what Scott has suggested.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39791773
The method I suggest actually is a server method.  

I prefer to send my mail through a third party smtp service for form input, one off emails and marketing mail.   While you can use your own server to do this 'for free' I find it is a good habit to use a  mail service.   For one thing, you can use the same code for all of your mail into one function.  When you do form input, you probably want mail to go to both yourself and the person filling out the form.  

By using the third party service, your outgoing mail is less likely to end up in the trash.  Think about how confusing email is for the non tech.  If somebody claims they did not get your automated mail, you may have to have them white list you in several places in including their webmail/server, their client email and some people will run multiple anti virus/spam software titles all of which have their own anti spam algo's.    

When you send your mail via your server, it is going to be very likely it is marked as spam especially if you are on a shared server where you are paying $10 or $20 bucks a month for hosting.  

While the mandril option is free to a point (11,000 monthly emails), it is a good idea to spend the $30 bucks a month on a dedicated IP.  I personally use both sendgrid.com and mandrill.  Another benefit is you can track your email stats and bounces a lot easier.  If you are on a shared server, it is very difficult to handle bounces.

I hope this makes sense.

Best of luck on your project.
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39799616
Thought this may be if some interest. An article I've written on mailto vs server side email
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/HTML/A_12871-Avoiding-mailto-and-how-to-capture-a-web-enquiry.html
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39804159
Good Article Rob
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39804604
Thanks Scott.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question