0

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`>&nbsp;&nbsp;&nbsp;&nbsp;
<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?

0

5 Answers 5

3

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.

  1. use mhtml to create a composite MIME attachment (works with MS clients but not much else, requires a lot of re-writing of code)

  2. use data uris (requires a fairly up to date client but only needs minimal changes to your code)

Sign up to request clarification or add additional context in comments.

Comments

1

You have to put the full link to the image, so http://yoursite.com/path/hulaminlogo.jpg

Comments

1

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.

2 Comments

` $mail->MsgHTML(" <body> <img src='domain/images/logo.png'><br> <br> <h3>Load Number $loadnumber has been revokedLOC.</h3><br> </body> ");`
sorry @Mateusz Rogulski, think we missed each other there. this does not work. any ideas on how to format the syntax?
1

For email, you need to add URL path to the image <img> src

<img src='http://www.YOUR_SITE.com/hulaminlogo.jpg'>&nbsp;&nbsp;&nbsp;&nbsp;

1 Comment

Use single quotes around the path '
1

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>
&nbsp;This is a test of PHPMailer.<br>
<br>
This particular example uses <strong>HTML</strong>, with a &lt;div&gt; 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

1 Comment

Thanks, I added this with $mail->AddAttachment('images/logo.png'); but how do I call it in my <body>?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.