Solved

Insert Table into email from HTML

Posted on 2014-01-10
8
984 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 43

Expert Comment

by:Rob
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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 43

Accepted Solution

by:
Rob 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 43

Expert Comment

by:Rob
ID: 39804604
Thanks Scott.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

860 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