Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 876793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:29:31+00:00 2026-05-15T11:29:31+00:00

I know how to embed an image into an email as an attachment, but

  • 0

I know how to embed an image into an email as an attachment, but that’s not really what I want to do. What I want to do is embed an image into the message and use that within the body of the email message itself. Is it possible to do this or possibly reference an attached file somehow to be used in the message?

Should I even worry about this? Is it more beneficial to just load them via a link to the image on my network? I was thinking that this would take some load off my server so it didn’t have to be downloaded directly from my site in every email message that got opened, thus reducing bandwidth a little.

Note: I’m not looking for any email frameworks or libraries etc, just for a simple way to accomplish this task.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:29:32+00:00Added an answer on May 15, 2026 at 11:29 am

    People will chime in to tell you to use SwiftMailer or some other library. But it’s not that hard. It’s really finicky, but not hard. Below is a function I use. I’ve anonymized it a bit, and hopefully didn’t break anything. In the html message (which I get from another function), link to your attached image this way:

    $output .= '<p><img src="cid:' . $linkID . '" alt="graph" /></p>';
    

    Where $linkID is the same value used in the function below.

    public function sendEmail($emailAddress)
    {
        $random_hash = md5(date('r', time()));
    
        $htmlString = $this->getHTML($random_hash);
    
        $message = "--mixed-$random_hash\n";
        $message .= 'Content-Type: multipart/alternative; boundary="alt-' . $random_hash . '"' . "\n\n";
        $message .= 'MIME-Version: 1.0' . "\n";
        $message .= '--alt-' . $random_hash . "\n";
        $message .= 'Content-Type: text/plain; charset="iso-8859-1"' . "\n";
        $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
    
        // text message
        $message .= strip_tags($htmlString) . "\n\n";
    
        $message .= '--alt-' . $random_hash . "\n";
        $message .= 'Content-Type: text/html; charset="iso-8859-1"' . "\n";
        // $message .= 'MIME-Version: 1.0' . "\n";
        $message .= 'Content-Transfer-Encoding: 7bit' . "\n\n";
    
        // html message
        $message .= $htmlString . "\n\n";
    
        $message .= '--alt-' . $random_hash . '--' . "\n";
    
        // graph image
        if($this->selectedGraph != 0)
        {
            $graphString = $this->getGraph();
            $graphString = chunk_split(base64_encode($graphString));
    
            $linkID = 'graph-' . $random_hash . '-image';
    
            $message .= '--mixed-' . $random_hash . "\n";
            $message .= 'MIME-Version: 1.0' . "\n";
            $message .= 'Content-Transfer-Encoding: base64' . "\n";
            $message .= 'Content-ID: ' . $linkID . "\n";
            $message .= 'Content-Type: image/gif; name="graph.gif"' . "\n";
            $message .= 'Content-Disposition: attachment' . "\n\n";
    
            $message .= $graphString;
            $message .= '--mixed-' . $random_hash . '--' . "\n";
    
        }
        else
        {
            $message .= '--mixed-' . $random_hash . '--' . "\n";
        }
    
    
        $headers = 'From: ' . $this->from. "\r\nReply-To: " . $this->replyto;
        $headers .= "\r\nContent-Type: multipart/related; boundary=\"mixed-" . $random_hash . "\"\r\nMIME-Version: 1.0";
    
        $flags = '-f ' . BOUNCED_EMAIL_ADDRESS;
    
        return mail($emailAddress, $this->subject, $message, $headers, $flags);
    
    }
    

    Whether or not it’s worthwhile to do is another question. If you attach the image, you’re using bandwidth to send the message out. Maybe it’s better for you to use the bandwidth all at once rather than spread out? Maybe not.

    I didn’t use attached images until I had to send out a different image to each recipient. I wasn’t about to store and manage all of those images on our server (and try to uniquely name them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.