CkPerl Requires Chilkat v11.0.0+
CkPerl
Build an AMP email with text and HTML fallbacks
See more Email Object Examples
Place text/x-amp-html inside multipart/alternative, before the regular HTML alternative. Use the AMP email validator and meet your provider’s sender requirements before using a dynamic campaign. AMP email MIME structure.
Chilkat CkPerl Downloads
use chilkat();
$success = 0;
# Assumes Chilkat is unlocked. See Global Unlock Sample.
$email = chilkat::CkEmail->new();
$email->put_From('Workshop team <events@example.com>');
$success = $email->AddTo("Alex Rivera",'alex@example.net');
if ($success != 1) {
print $email->lastErrorText() . "\r\n";
exit;
}
$email->put_Subject("Workshop reminder");
$email->put_Body("Your workshop starts at 09:00.");
$mimeBytes = chilkat::CkBinData->new();
$success = $email->GetMimeBd($mimeBytes);
if ($success != 1) {
print $email->lastErrorText() . "\r\n";
exit;
}
$mime = chilkat::CkMime->new();
$success = $mime->LoadMimeBd($mimeBytes);
if ($success != 1) {
print $mime->lastErrorText() . "\r\n";
exit;
}
$success = $mime->ConvertToMultipartAlt();
if ($success != 1) {
print $mime->lastErrorText() . "\r\n";
exit;
}
# Append the specialist part before the standard HTML fallback.
$special = chilkat::CkMime->new();
$special->put_ContentType("text/x-amp-html");
$special->put_Charset("utf-8");
$special->SetBody("<!doctype html><html amp4email><head><meta charset='utf-8'><style amp4email-boilerplate>body{visibility:hidden}</style><script async src='https://cdn.ampproject.org/v0.js'></script></head><body><p>Your workshop starts at 09:00.</p></body></html>");
$success = $mime->AppendPart($special);
if ($success != 1) {
print $mime->lastErrorText() . "\r\n";
exit;
}
$standard = chilkat::CkMime->new();
$standard->put_ContentType("text/html");
$standard->put_Charset("utf-8");
$standard->SetBody("<p>Your workshop starts at <b>09:00</b>.</p>");
$success = $mime->AppendPart($standard);
if ($success != 1) {
print $mime->lastErrorText() . "\r\n";
exit;
}
$success = $mime->SaveMime("amp.eml");
if ($success != 1) {
print $mime->lastErrorText() . "\r\n";
exit;
}
print "Saved amp.eml." . "\r\n";