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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.