I am trying to include an image into my message in phpmailer. The following is my code, Mails are being sent but without the embeded image, instead they're appear to be attached to the email. Not sure what is wrong with my code, please help?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<?php
require_once('class.phpmailer.php');
require_once('class.smtp.php');
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->From = "xxxxx";
$mail->FromName = "Jan Nowak";
$mail->AddReplyTo('xxxx');
$mail->Host = "xxxxxx";
$mail->Mailer = "smtp";
$mail->SMTPAuth = true;
$mail->Username = "xxxxx";
$mail->Password = "xxxxxx";
$mail->Port = xxx; usługi poczty
$mail->Subject = "temat";
$mail->Body = 'treść maila';
$mail->IsHTML(true);
$mail->AddEmbeddedImage('images/Kartka.png', 'Kartka');
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
"<p>This is a test picture: <img src=\"images/Kartka.png\" /></p>";
//$mail->addAttachment ('images/Kartka.jpg');
$mail->AddAddress ("xxxxx");
if($mail->Send())
{
echo 'E-mail został wysłany';
}
else
{
echo 'E-mail nie mógł zostać wysłany';
}
?>
</html>
</head>
If you're a PHP application developer, you might need to send email notifications through your custom PHP applications. With XAMPP, there are two ways to do this: you can use the included sendmail.exe binary, or you can use the third-party PHPMailer class.
The PHPMailer library provides the easiest way to send an email from localhost with an SMTP server using PHP. Not only the text email, but you can also send HTML email from localhost in PHP using PHPMailer.
PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *. secureserver. * ).
Add on the <img>
tag put src='cid:Kartka'
$mail->AddEmbeddedImage('images/Kartka.png', 'Kartka');
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
"<p>This is a test picture: <img src=\"cid:Kartka\" /></p>";
Why you use so much \ ?? you can do it also like this :
<img src="cid:Kartka"/>
Add this tag where you want the image to appear in the body
$mail->Body = "... <img src='cid:logo.png> ..";
$mail->AddEmbeddedImage($_SERVER['DOCUMENT_ROOT']."[path_to_image] logo.png",'logo.png','logo.png');
Works in Outlook and all other email client software
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With