PhPmailier detect if inline image exist and how to embed if it is a copied from internet ?

Alex Lord
Alex Lord used Ask the Experts™
on
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';

$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");

$mail->AddAddress("email@example.com");
$mail->Subject = "Test 1";

$mail->IsHTML(true);
$mail->AddEmbeddedImage('logo.jpg', 'logoimg', 'logo.jpg'); // attach file logo.jpg, and later link to it using identfier logoimg
$mail->Body = "<h1>Test 1 of PHPMailer html</h1>
    <p>This is a test picture: <img src=\"cid:logoimg\" /></p>";
$mail->AltBody="This is text only alternative body.";

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter is sent";
}
?>

Open in new window



im looking at this example,

how can i use this for inline images copied into the email body and how can i even tell if their is a img in the body ?

cause not all users will embed a image inline on email ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
PHPMailer does have a function to add an embedded image you can read more about it here http://phpmailer.github.io/PHPMailer/classes/PHPMailer.PHPMailer.PHPMailer.html#method_addEmbeddedImage

The other option is to reference the image from a server resource in other words just put a link in for the img.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Re-read your question - not sure what you are asking - the sample you posted already shows the use of addEmbeddedImage?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial