Jump to content

Sending HTML email with image


pitris

Recommended Posts

Hi,

 

I'm trying to send an HTML email, which includes an image, and contains some portuguese language specific characters, using phpmailer.

 

My code looks like this:

 

        require_once('phpmailer_v2.3/class.phpmailer.php');
        $mail = new PHPMailer();
        $mail->IsSMTP(); // send via SMTP
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = EMAIL_USERNAME; // SMTP username
        $mail->Password = EMAIL_PASSWORD; // SMTP password
        $mail->From = EMAIL_FROM;
        $mail->FromName = EMAIL_FROMNAME;
        $mail->AddAddress($email);
        $mail->WordWrap = 50; // set word wrap
        $mail->IsHTML(true); // send as HTML
        $mail->CharSet = "utf-8";
        $mail->AddEmbeddedImage('myimg.png','myimg','myimg.png');

        $MailBody = '<HTML><BODY><IMG SRC="cid:myimg><br><br>'.$EmailTextPT.
                    "<br><br><br>".EMAIL_FOOTER."</BODY></HTML>";           
        $mail->Subject = utf8_encode(EMAIL_SUBJECT);
        $mail->Body = utf8_encode($MailBody);
        $result = $mail->Send();

 

$EmailTextPT contains some text with Portuguese characters. The email subject also contains some Portuguese characters.

 

The email is sent but when I open it in gmail it's not recognized as an html email (the body is displayed as plain text with the html tags "showing" and the image is received as an attachment). When I open the email in mac os x email client, I only see the subject and the image, but the text is absent.

 

What am I doing wrong?

 

Thanks in advance,

Pedro

Link to comment
https://forums.phpfreaks.com/topic/143749-sending-html-email-with-image/
Share on other sites

you need to specify if the image is inline or attachment plus you need the content type of the image, if you just want to show the image inside your html then you must link it to the existing image ion your server eg, <img src='servername/imeages/imagename.jpg'> this will be easiest.

 

you can not send an image in an email without inserting it into the header, if u just want to show the email then you should link to the remote server where the image is, you dont send images as attachments man unless u have to.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.