Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PHP ActiveX Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip

HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PHP ActiveX) SendGrid HTML Email with Embedded Images

Demonstrates how to send an HTML email with embedded images using SendGrid.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Note: The php_com_dotnet.dll may need to be enabled inside of php.ini.

<?php

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code

$req = new COM("Chilkat_9_5_0.HttpRequest");
$http = new COM("Chilkat_9_5_0.Http");

// First.. load a JPG file and build an HTML img tag with the JPG data inline encoded.
// Our HTML img tag will look like this:
// <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA3ADcAA..." alt="" style="border-width:0px;" />
$bdJpg = new COM("Chilkat_9_5_0.BinData");
$success = $bdJpg->LoadFile('qa_data/jpg/starfish.jpg');
if ($success == 0) {
    print 'Failed to load JPG file.' . "\n";
    exit;
}

$sbHtml = new COM("Chilkat_9_5_0.StringBuilder");
$sbHtml->Append('<html><body><b>This is a test<b><br /><img src=\'data:image/jpeg;base64,');
// Append the base64 image data to sbHtml.
$bdJpg->GetEncodedSb('base64',$sbHtml);
$sbHtml->Append('\' alt=\'\' style=\'border-width:0px;\' /></body></html>');

$json = new COM("Chilkat_9_5_0.JsonObject");
$json->UpdateString('personalizations[0].to[0].email','matt@chilkat.io');
$json->UpdateString('from.email','admin@chilkatsoft.com');
$json->UpdateString('subject','Test HTML email with images');
$json->UpdateString('content[0].type','text/html');
$json->UpdateSb('content[0].value',$sbHtml);

$http->AuthToken = 'SENDGRID_API_KEY';

// resp is a Chilkat_9_5_0.HttpResponse
$resp = $http->PostJson3('https://api.sendgrid.com/v3/mail/send','application/json',$json);
if ($http->LastMethodSuccess != 1) {
    print $http->LastErrorText . "\n";
}
else {
    // Display the JSON response.
    print $resp->BodyStr . "\n";

}


?>

 

© 2000-2020 Chilkat Software, Inc. All Rights Reserved.