Reputation: 10809
I have a PHP Script to send an email using PHP mail.
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML("
<body>
<img src=`hulaminlogo.jpg`>
<br>
<h3>Load Number $loadnumber has been revoked by LOC.</h3><br>
</body>
");
$mail->Send();
The MsgHTML, works correctly however the <img src="hulaminlogo.jpg">
does not display. I have tried with '' as well. " does not work as it ends the value MsgHTML.
How can I correctly format this syntax so the image displays correctly?
Upvotes: 0
Views: 522
Reputation: 5755
Add the image as an attachment to your message
UPD:
<body style="margin: 10px;">
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<div align="center"><img src="images/phpmailer.gif" style="height: 90px; width: 340px"></div><br>
<br>
This is a test of PHPMailer.<br>
<br>
This particular example uses <strong>HTML</strong>, with a <div> tag and inline<br>
styles.<br>
<br>
Also note the use of the PHPMailer logo above with no specific code to handle
including it.<br />
Included are two attachments:<br />
phpmailer.gif is an attachment and used inline as a graphic (above)<br />
<br />
PHPMailer:<br />
Author: Andy Prevost ([email protected])<br />
Author: Marcus Bointon ([email protected])<br />
</div>
</body>
and then you send that
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif');
that's it
Upvotes: 1
Reputation: 48387
Nikola is correct that adding the full url to the img will alow the client to find and render the content - but by default most browsers won't go fetch content unles explicitly told to do so. Simply adding the iage as an attachment won't help - some MUAs might render it, most won't. There's 2 options for embedding the image within the email.
use mhtml to create a composite MIME attachment (works with MS clients but not much else, requires a lot of re-writing of code)
use data uris (requires a fairly up to date client but only needs minimal changes to your code)
Upvotes: 3
Reputation: 126
For email, you need to add URL path to the image <img>
src
<img src='http://www.YOUR_SITE.com/hulaminlogo.jpg'>
Upvotes: 1
Reputation: 7455
Noticed that, ms outlook
have some strange bahaviours. So I suggest you to use only absolute url of your images.
This soolution gives you the best results.
Upvotes: 1
Reputation: 15048
You have to put the full link to the image, so http://yoursite.com/path/hulaminlogo.jpg
Upvotes: 1