Envoi d’un email HTML avec du texte comme corps alternatif

Envoi d’un email HTML avec du texte comme corps alternatif :

use Zend\Mail;
use Zend\Mime\Message as MimeMessage;
use Zend\Mime\Part as MimePart;

$htmlPart = new MimePart($htmlBody);
$htmlPart->type = "text/html";
  
$textPart = new MimePart($textBody);
$textPart->type = "text/plain";
  
$body = new MimeMessage();
$body->setParts(array($textPart, $htmlPart));
  
$message = new Mail\Message();
$message->setFrom($from);
$message->addTo($to);
$message->setSubject($subject);
  
$message->setEncoding("UTF-8");
$message->setBody($body);
$message->getHeaders()->get('content-type')
                      ->setType('multipart/alternative');
  
$transport = new Mail\Transport\Sendmail();
$transport->send($message);

Leave a Reply