Monday, May 25, 2015

Add embedded image in email through PHPMailer

Add embedded image in email through PHPMailer

<?php
  $mailer = new PHPMailer();

  $mailer->IsSMTP(); // telling the class to use SMTP
  $mailer->Host = 'localhost'; // SMTP server
  #$mailer->SMTPDebug = 2; // enables SMTP debug information (for testing)
                          // 1 = errors and messages
                          // 2 = messages only
  $mailer->Subject = 'My subject';
  $mailer->AddAddress($email, '');

  $mailer->SetFrom('do-not-reply@mydomain.com', 'My Name');

  $html = '<img src="cid:logo">';

  $mailer->MsgHTML($html . "\n");

  $mailer->AddEmbeddedImage('/tmp/logo.png', 'logo', 'logo.png');
  $mailer->AddAttachment($attach);

  if(!$mailer->Send()) {
    echo "[ERR] Mailer Error: " . $mailer->ErrorInfo . "\n";
  }
?>

No comments: