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 687889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:10:24+00:00 2026-05-14T02:10:24+00:00

The following $header is being sent via PHP’s mail($to,$subject,$content,$header) command. The mail arrives and

  • 0

The following $header is being sent via PHP’s mail($to,$subject,$content,$header) command. The mail arrives and appears to have an attachment. But the mail text is empty as is the file. I think this has something to do with line spacing but I can’t see the problem. I have tried putting the contents (between the boundaries) in $contents rather than appending it to $header. It doesn’t make a difference. Any thoughts?

From: dnagirl@someplace.com 
Reply-To: dnagirl@someplace.com 
X-Mailer: PHP 5.3.1
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="7425195ade9d89bc7492cf520bf9f33a"

--7425195ade9d89bc7492cf520bf9f33a
Content-type:text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

this is a test message.

--7425195ade9d89bc7492cf520bf9f33a
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"

JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k
ZT4+CnN0cmVhbQp4nE2PT0vEMBDFadVdO4p/v8AcUyFjMmma5CqIIF5cctt6WnFBqLD1+4Np1nY3
c3lvfm+GyQ4VaUY11iQ2PTyuHG5/Ibdx9fIvhi3swJMZX24c602PTzENegwUbNAO4xcoCsG5xuWE
.
... the rest of the file
.
MDAwMDA2MDYgMDAwMDAgbiAKMDAwMDAwMDcwNyAwMDAwMCBuIAowMDAwMDAxMDY4IDAwMDAwIG4g
CjAwMDAwMDA2NDcgMDAwMDAgbiAKMDAwMDAwMDY3NyAwMDAwMCBuIAowMDAwMDAxMjg2IDAwMDAw
IG4gCjAwMDAwMDA5MzIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSAxNCAvUm9vdCAxIDAgUiAv
SW5mbyAyIDAgUgovSUQgWzxEMURDN0E2OUUzN0QzNjI1MDUyMEFFMjU0MTMxNTQwQz48RDFEQzdB
NjlFMzdEMzYyNTA1MjBBRTI1NDEzMTU0MEM+XQo+PgpzdGFydHhyZWYKNDY5MwolJUVPRgo=


--7425195ade9d89bc7492cf520bf9f33a--

$header ends without a line break

  • 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-14T02:10:25+00:00Added an answer on May 14, 2026 at 2:10 am

    I use the code below to send a message with an attachment as well as html and text message parts. I remember fighting with it a long time to get it right, but unfortunately don’t remember which parts were my problems. Maybe looking at it will help you out. I’ve changed some irrelevant variables and hopefully made it easier to read. Feel free to ask if something is weird or unclear and I’ll try to explain.

    public function sendEmail($htmlString)
    {
        $random_hash = md5(date('r', time()));
    
        $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 .= '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(); // image attachment
            $graphString = chunk_split(base64_encode($graphString));
    
            $linkID = 'graph-' . $userInfo['FirmID'] . $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($userInfo['Email'], $this->subject, $message, $headers, $flags);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php object(??? new to this). It is being sent through
Is the following From header incorect? // To send HTML mail, the Content-type header
I'm currently writing out xml and have done the following: header (content-type: text/xml); header
i am using the following code <?php $rFile = $_GET['sfile']; $rExt = $_GET['ext']; header(Content-disposition:
I have the following response being sent from a server. How do i extract
I have the following problem: A PHP Script is called via Ajax. The script
I have the following code in header.php to echo the body's id: <body id=<?php
I have an ant script with the following header: <project name=Simple ActiveJDBC Example default=clean
I have the following: in header: <script type=text/JavaScript> $(document).ready(function() { $(.modal).fancybox({ // for modals
I set a header in the following way: header('Content-Length: ' . filesize($strPath)); On my

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.