How to use a html email signature that is hosted online? - php
for my email signature I want to use a hosted HTML code that is generated through a PHP script, since I may want to change information of the signature I really want that hosted solution to be sure that not only mails in the future, but also sent mails have the "new" signature.
I have a PHP script behind "tld.com/signature/my#mail.com" (yes, no .php ending) waiting for a call. If i open that domain it will output valid HTML code.
But how can I embed the output in my mails as html signature?
Iframes are not an option, since they dont work everywhere.
Html img tags dont work since that url doesnt output an image.
Any ideas? :-) - Thanks!
As far as I can see image and iframe are the only way of achieving this, though you could possibly use dynamic css too; either way, your signature generation API would need to change, or at least be wrapped.
A blog post here details how the author went about doing just this for posting dynamic scores on a user's Facebook wall.
This is the workflow they used:
As the score had to be dynamic, what they did was create an API to take a snapshot image of the HTML content which the client could then show.
They created an API endpoint which would
Query the score HTML generator endpoint (in your case signature generation) to generate the HTML you want the client to display.
Turn the HTML into PDF using the HTML2PDF utility for PHP 5.2.
Render the PDF into an image which can then be returned to the user for displaying using PHP::ImageMagick.
They did this with the following code:
$html2pdf = new HTML2PDF('P', 'A4');
$html2pdf->writeHTML($html_content);
$file = $html2pdf->Output('temp.pdf','F');
$im = new imagick('temp.pdf');
$im->setImageFormat( "jpg" );
$img_name = time().'.jpg';
$im->setSize(800,600);
$im->writeImage($img_name);
$im->clear();
$im->destroy();
The image returned by this API can then be rendered into an image tag for display to the client. There is a demo of this workflow in action available here.
Related
PNG image required to be converted from JSON and email
So I have used a signature pad from another source and the pad works fine. When I submit the form, it saves the image as JSON code and this is useful as I need to store it within a database as well. However upon submission, I need to convert the code to png and email the image. This is the code I use to convert the code to image, $output2 is the JSON code from the signature capture, signature-to-image.php is the file actually converting the image: require_once 'signature-to-image.php'; $img = sigJsonToImage($output2); // Save to file imagepng($img); // Destroy the image in memory when complete - I destroy the image at the very end of the PHP file This code converts the code fine as I have tested it opening a header with just $img in it and the image appears fine. However when I try to add the png image to the body of the email, it just shows up as Resource id#7. I use the line of code below to send the image: $email_message .= "Signature: ".clean_string($img)."\n"; I am assuming I need to either embed the image within the body of the email (which I am unfamiliar with) or I need to send the image as an attachment (which I am also unfamiliar with). Am I correct in thinking this? which option is the better choice or is there a better alternative? So I write in the signature pad, it captures the signature and saves the image in JSON (as far as I am aware, I have zero experience using JSON) This is an example of the output I would receive: [{"lx":46,"ly":49,"mx":46,"my":48},{"lx":46,"ly":48,"mx":46,"my":49},{"lx":46,"ly":51,"mx":46,"my":48},{"lx":46,"ly":55,"mx":46,"my":51},{"lx":46,"ly":62,"mx":46,"my":55},{"lx":47,"ly":69,"mx":46,"my":62},{"lx":52,"ly":94,"mx":47,"my":69},{"lx":54,"ly":105,"mx":52,"my":94},{"lx":56,"ly":114,"mx":54,"my":105},{"lx":58,"ly":126,"mx":56,"my":114},{"lx":59,"ly":133,"mx":58,"my":126},{"lx":60,"ly":136,"mx":59,"my":133},{"lx":60,"ly":140,"mx":60,"my":136},{"lx":88,"ly":25,"mx":88,"my":24},{"lx":88,"ly":24,"mx":88,"my":25},{"lx":88,"ly":28,"mx":88,"my":24},{"lx":89,"ly":33,"mx":88,"my":28},{"lx":90,"ly":39,"mx":89,"my":33},{"lx":91,"ly":43,"mx":90,"my":39},{"lx":93,"ly":60,"mx":91,"my":43},{"lx":94,"ly":69,"mx":93,"my":60},{"lx":96,"ly":79,"mx":94,"my":69},{"lx":98,"ly":94,"mx":96,"my":79},{"lx":99,"ly":102,"mx":98,"my":94},{"lx":100,"ly":114,"mx":99,"my":102},{"lx":100,"ly":117,"mx":100,"my":114},{"lx":100,"ly":118,"mx":100,"my":117},{"lx":100,"ly":120,"mx":100,"my":118},{"lx":28,"ly":116,"mx":28,"my":115},{"lx":28,"ly":115,"mx":28,"my":116},{"lx":28,"ly":114,"mx":28,"my":115},{"lx":30,"ly":113,"mx":28,"my":114},{"lx":32,"ly":112,"mx":30,"my":113},{"lx":36,"ly":110,"mx":32,"my":112},{"lx":57,"ly":104,"mx":36,"my":110},{"lx":67,"ly":100,"mx":57,"my":104},{"lx":91,"ly":92,"mx":67,"my":100},{"lx":121,"ly":75,"mx":91,"my":92},{"lx":127,"ly":72,"mx":121,"my":75},{"lx":129,"ly":72,"mx":127,"my":72},{"lx":130,"ly":72,"mx":129,"my":72},{"lx":130,"ly":73,"mx":130,"my":72},{"lx":196,"ly":48,"mx":196,"my":47},{"lx":196,"ly":47,"mx":196,"my":48},{"lx":198,"ly":45,"mx":196,"my":47},{"lx":200,"ly":43,"mx":198,"my":45},{"lx":204,"ly":42,"mx":200,"my":43},{"lx":209,"ly":41,"mx":204,"my":42},{"lx":219,"ly":40,"mx":209,"my":41},{"lx":232,"ly":39,"mx":219,"my":40},{"lx":238,"ly":39,"mx":232,"my":39},{"lx":244,"ly":39,"mx":238,"my":39},{"lx":257,"ly":38,"mx":244,"my":39},{"lx":261,"ly":38,"mx":257,"my":38},{"lx":263,"ly":38,"mx":261,"my":38},{"lx":223,"ly":42,"mx":223,"my":41},{"lx":223,"ly":41,"mx":223,"my":42},{"lx":223,"ly":44,"mx":223,"my":41},{"lx":223,"ly":45,"mx":223,"my":44},{"lx":223,"ly":50,"mx":223,"my":45},{"lx":223,"ly":52,"mx":223,"my":50},{"lx":223,"ly":56,"mx":223,"my":52},{"lx":223,"ly":75,"mx":223,"my":56},{"lx":223,"ly":84,"mx":223,"my":75},{"lx":223,"ly":91,"mx":223,"my":84},{"lx":223,"ly":110,"mx":223,"my":91},{"lx":223,"ly":119,"mx":223,"my":110},{"lx":223,"ly":123,"mx":223,"my":119},{"lx":223,"ly":127,"mx":223,"my":123},{"lx":222,"ly":129,"mx":223,"my":127},{"lx":221,"ly":129,"mx":222,"my":129},{"lx":219,"ly":130,"mx":221,"my":129},{"lx":217,"ly":130,"mx":219,"my":130},{"lx":211,"ly":131,"mx":217,"my":130},{"lx":201,"ly":131,"mx":211,"my":131},{"lx":192,"ly":132,"mx":201,"my":131},{"lx":181,"ly":132,"mx":192,"my":132},{"lx":177,"ly":132,"mx":181,"my":132},{"lx":173,"ly":132,"mx":177,"my":132},{"lx":163,"ly":132,"mx":173,"my":132},{"lx":161,"ly":132,"mx":163,"my":132},{"lx":159,"ly":132,"mx":161,"my":132},{"lx":161,"ly":132,"mx":159,"my":132},{"lx":166,"ly":131,"mx":161,"my":132},{"lx":172,"ly":130,"mx":166,"my":131},{"lx":176,"ly":130,"mx":172,"my":130},{"lx":192,"ly":130,"mx":176,"my":130},{"lx":203,"ly":130,"mx":192,"my":130},{"lx":211,"ly":130,"mx":203,"my":130},{"lx":219,"ly":130,"mx":211,"my":130},{"lx":222,"ly":130,"mx":219,"my":130},{"lx":228,"ly":130,"mx":222,"my":130},{"lx":232,"ly":130,"mx":228,"my":130},{"lx":235,"ly":130,"mx":232,"my":130},{"lx":240,"ly":130,"mx":235,"my":130},{"lx":241,"ly":130,"mx":240,"my":130},{"lx":242,"ly":130,"mx":241,"my":130},{"lx":243,"ly":130,"mx":242,"my":130},{"lx":246,"ly":130,"mx":243,"my":130},{"lx":250,"ly":129,"mx":246,"my":130},{"lx":261,"ly":128,"mx":250,"my":129},{"lx":265,"ly":128,"mx":261,"my":128},{"lx":267,"ly":127,"mx":265,"my":128},{"lx":269,"ly":127,"mx":267,"my":127}]
png attachment generated by an API in phpmailer
I'm trying to send a .png image to my user via phpmailer. The image is shown when I use <img> tags, but I want it to display as a real attachment that the user can open/save/print (like in this screenshot). I read that I can use $mail->addStringAttachment for this. So I tried this, and it does send an attachment with the email, but when I try to open it, it says that Windows Picture Viewer can't open the file. Also saving to my computer and then opening with Paint doesn't work, it tells me thats not a valid file or something. I think this is because it's no static image, but an image generated by an API, namely: $qr = 'http://api.qrserver.com/v1/create-qr-code/?data=' . $guid . '&size=250x250'; So this image should be sent as an attachment. Does anyone know how I can make this work?
I got it to work fine as an attachment by doing the following: $qr = file_get_contents("https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example"); $mail->addStringAttachment($qr, "qr.png");
The reason it's failing is that you're trying to attach the URL as image data. You need to fetch the data from the URL first, then attach it to something. Go one step at a time - make sure that you're getting back valid image before trying to email it - e.g. file_put_contents('qr.png', file_get_contents($qr)); and make sure you get a valid image saved in there. When you know that's working, then try and email it with $mail->addStringAttachment(file_get_contents($qr) 'qr.png'); Though perhaps with a bit more error checking!
Can I use PHP in a email signature?
I have a question. I would like to add rotating links inside my email signature to track results on my site. I can make these dynamic tracking urls on google as you may know but I would like to rotate them inside my email signature to see which text draws the most conversions or returning visitors. Is this possible? I found this for instance: $mybanners[1] = '<img src="banner1.jpg">'; $mybanners[2] = '<img src="banner1.jpg">'; $id = rand(1,2); echo $mybanners[$id]; But when I look into my windows live mail I can only upload html files. Does someone know how to do this?
You can't provide PHP scripts in a mail, since it is a server-side language and it will be opened by a mail client. Even Javascript is very often blocked for security reason. What you can do is make a "fake" image which will be in fact generate by a PHP script. YOu can find inspiration by looking to script made for forum avatar rotation. The idea is to generate an image, which will be displayed to the client but, in the same time, save some data about the user who requests the image if you want: <?php // Save whatever you want about the user file_put_content("log/user.txt", $_SERVER['HTTP_REFERER']); // Render a valid PNG image header('Content-Type: image/png'); readfile("/path/to/banner.png"); ?> This script should be used as a standard image (with, if you want, a nice URL rewrite to make a .png link): <img src="http://www.example.com/my_super_banner.php" /> where my_super_banner.php is the script described before.
How to add graph to website?
I'm a beginner here and need help. I have this code, which works and outputs a graph in my browser (if this is the only code in php file). I don't know how to add text below or above just like any other site. When I try, it returns my whole code in the browser. How do I go on about this? <?php // content="text/plain; charset=utf-8" require_once ('jpgraph/src/jpgraph.php'); require_once ('jpgraph/src/jpgraph_line.php'); // Some data $ydata = array(11,3,8,12,5,1,9,8,5,7); // Create the graph. These two calls are always required $graph = new Graph(350,250); $graph->SetScale('textlin'); // Create the linear plot $lineplot=new LinePlot($ydata); $lineplot->SetColor('blue'); // Add the plot to the graph $graph->Add($lineplot); // Display the graph $graph->Stroke(); ?> Thanks in advance!
What you need is quite simply: <img src="graph.php"> Put that in a separate HTML file or PHP script. You cannot output the image and text in the same script / web page. It needs to be separated. Don't worry about the .php extension for the image src= attribute. It will display despite the lack of .jpeg extension. (The Graph class already outputs the correct MIME type I assume.)
I'm a bit rusty on PHP, but I believe that all "require" are supposed to be made before any content is output. Otherwise, the normal HTML/XHTML syntax and formatting take precedence.
I haven't actually used this library, but I'm assuming the image is output directly to the browser. It's probably easiest to create a new HTML document (or whatever the rest of your site is powered by) and include this as an image, with the image's src being the name of this script.
HTML2FPDF print page results as pdf
I'm trying to user HTML2FPDF (http://html2fpdf.sourceforge.net/) to create a PDF of a page, but I can't seem to get it to work properly. My page consists of jQuery to show a graph. I want the graph and other text on the page to be exported as a PDF. http://portal.flyingstartlifestyle.360southclients.com/leanne/leanne.php <- the graph with the html2fpdf code at the bottom of the page. HTML2FPDF code: function createPDF() { define('ABSPATH', dirname(__FILE__).'/'); require(ABSPATH.'classes/pdf/html2fpdf.php'); $pdf = new HTML2FPDF(); $pdf->AddPage(); $html = ob_get_contents(); //$html = htmlspecialchars($html); if ($html) { $fileName = "testing.pdf"; $pdf->WriteHTML($html); $pdf->Output("pdfs/".$fileName); echo "<p>PDF file is generated successfully! Click here to open it.</p>"; } else { echo "<p>There has been an error in creating your PDF.</p>"; }; }; If I unhide the line "$html = htmlspecialchars($html);" it prints the pdf the text of the page, otherwise it creates an empty PDF. Any ideas how I can transfer my graph to a PDF? Cheers
A few years back, I've been beating my head against the wall trying to convert HTML into PDF for days. What I wanted to do was really simple - make an invoice for customers into a PDF file. An image (logo) up on top, a few paragraphs, and a table with a list of charges. The hole shaped like my head on the wall is still there. All of the free libraries that convert things to PDF - they all suck. I found one that sucks the least, it's DomPDF. At least that one ended up doing the job, after a week of suffering and debugging. It's not fast by any means, though (if you want to generate a complex PDF, you might want to do it off-thread).
My page consists of jQuery to show a graph. I want the graph and other text on the page to be exported as a PDF. jQuery is interpreted by the browser and not by the server. When you send the HTML to be rendered into PDF, it will not run the Javascript. You'll need to find a way to actually generate the image some other way.
I guess I could see a situation where you could use ajax to make a remote call and send all of the html that the js sees. The remote call then would write a file of that html. The remote call would send back a file name for the pdf to be generated. Your js then could provide a link to the processing page of the html2pdf that references the file created from the remote call. This would work, but it might be a bit much. Regards.