Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP ActiveX Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

Convert Email HTML to Plain-Text Alternative

Loads an HTML email from a web page, converts the HTML to a plain-text alternative body, and sends it.

Download Chilkat Email ActiveX

Download Chilkat HTML-to-XML ActiveX (also includes HTML-to-PlainText conversion)

Download Chilkat MHT ActiveX

<?php

//  The mailman object is used for receiving (POP3)
//  and sending (SMTP) email.
$mailman = new COM("Chilkat.MailMan2");

//  The MHT component can be used to convert an HTML page
//  from a URL, file, or in-memory HTML into an email
//  with embedded images and style sheets.
$mht = new COM("Chilkat.Mht");

//  Any string argument automatically begins the 30-day trial.
$success = $mailman->UnlockComponent('30-day trial');
if ($success != true) {
    print 'MailMan component unlock failed' . "\n";
    exit;
}

$success = $mht->UnlockComponent('30-day trial');
if ($success != true) {
    print 'Mht component unlock failed' . "\n";
    exit;
}

$mht->UseCids = true;
$email = $mht->GetEmail('http://www.bonairefishing.com/');
if (is_null($email)) {
    print $mht->lastErrorText() . "\n";
    exit;
}

$email->Subject = 'Test HTML/plain-text email';

$email->AddTo('Chilkat Support','support@chilkatsoft.com');
$email->From = 'admin@chilkatsoft.com';

$h2t = new COM("Chilkat.HtmlToText");
$success = $h2t->UnlockComponent('Anything for 30-day trial');
if ($success != true) {
    print $h2t->lastErrorText() . "\n";
    exit;
}

//  Get the email's HTML body.

$html = $email->getHtmlBody();

//  Convert it to plain text:

$plainText = $h2t->toText($html);

//  Add a plain-text alternative to the email:
$email->AddPlainTextAlternativeBody($plainText);

$mailman->SmtpHost = 'mail.chilkatsoft.com';
$mailman->SmtpUsername = 'admin@chilkatsoft.com';
$mailman->SmtpPassword = '*myPassword5*';

$success = $mailman->SendEmail($email);
if ($success != true) {
    print $mailman->lastErrorText() . "\n";
    exit;
}

print 'HTML/plain-text Email Sent!' . "\n";
?>

Need a specific example? Send a request to support@chilkatsoft.com

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