How to embed images using PHPMailer?
|
|
|
|
|
Question: How to embed images using PHPMailer? This could be useful for newsletters. Answer: - Use the AddEmbeddedImage method provided by the PHPMailer class.
eg. $mail->AddEmbeddedImage('test.gif','testImage','test.gif'); - Parameters for AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream')
- $path = Path to the attachment
- $cid = Content ID of the attachment. Use this to identify the Id for accessing the image in an HTML form.
- $name = Overrides the attachment name.
- $encoding = File encoding
- $type = File extension (MIME) type.
Example:
<?php //Include the PHPMailer class include = 'class.phpmailer.php'; $mailer=new phpmailer(); $mailer->From =’
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
’; $mailer->FromName=’TechPortal'; $mailer->Subject =’TechPortal Example’; $mailer->AddAddress(’
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
’);
$mailer->IsHTML(true); $mailer->AddEmbeddedImage(’test.gif’,'testImage’,'test.gif’); $mailer->Body =’<img src=”cid:testImage”>’;
$mailer->Send(); ?> DOWNLOAD PHPMailer Class (Version: 2.0.4)
|