sending an html message with a plain text attachment
Posted: Wed Dec 19, 2007 1:25 am
I'm trying to send an HTML message with a plain text attachment for those email clients that are not HTML capable. My code looks like this:
The email sends successfully, however the original email is not in HTML format. I do get the plain text message, though.
I thought I might need to make it multi-part, but it's not a multi-part message (at least I don't think). It's just a message with an attachment.
Code: Select all
<?php
require_once 'lib/Swift.php';
require_once 'lib/Swift/Connection/SMTP.php';
$log = Swift_LogContainer::getLog();
$log->setLogLevel(4);
$smtp = new Swift_Connection_SMTP('smtp.1and1.com', 25);
$smtp->setUsername('noreply@example.com');
$smtp->setpassword('password');
$swift = new Swift($smtp);
$message = new Swift_Message('A simple subject', '<b>A</b> <strong><small>Simple</small> Body</strong>', 'text/html');
$attachment = new Swift_Message_Attachment('A Simple Body', 'email.txt', 'text/plain');
$message->attach($attachment);
if ($swift->send($message, 'me@anotherdomain.com', 'noreply@example.com'))
{
echo 'sent email';
} else
{
echo 'did not send email';
$log = Swift_LogContainer::getLog();
echo $log->dump(true);
}I thought I might need to make it multi-part, but it's not a multi-part message (at least I don't think). It's just a message with an attachment.