views:

166

answers:

1

What is the correct header information and MIME types for an email message with HTML content only, not mixed type (with both text and HTML).

Just to inform, I am using Swiftmailer (PHP) to this job.

+1  A: 

This is my code:

$swift = new stdClass();
$swift->transport = Swift_SendmailTransport::newInstance( '/usr/sbin/sendmail -bs' );
$swift->mailer = Swift_Mailer::newInstance( $swift->transport );
$swift->message = Swift_Message::newInstance('Title')
    ->setFrom( array('[email protected]' => 'Me') )
    ->setTo( array( '[email protected]' => 'Some One' ) )
    ->setBody('<h1>It works!</h1>', 'text/html');

You can also take a look at the Headers documentation on http://swiftmailer.org/docs/headers

jwandborg
I've done that, but it adds the contents of the message twice.I try to insert the html code without 'text/html' and inserting mime headers after:$headers = $message->getHeaders();if ($headers->has('MIME-Version')){ $MIME_Version = $headers->get('MIME-Version'); $MIME_Version->setValue('1.0');}else{ $headers->addTextHeader('MIME-Version', '1.0');}if ($headers->has('Content-type')){ $Content_type = $headers->get('Content-type'); $Content_type->setValue('text/html');}else{ $headers->addTextHeader('Content-type', 'text/html');}But incredibly the same error keeps happening
Paulocoghi
This is correct (in terms of programming), but the error still occurs
Paulocoghi
What are the errors you get?
jwandborg