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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:25:14+00:00 2026-06-18T05:25:14+00:00

Im having problems with line breaks when sending mail with php. The main issue

  • 0

Im having problems with line breaks when sending mail with php. The main issue here is, that the line breaks doesnt work in mails with attachment (multipart/mixed) but in plain text they do.

<?php
function sendMail($email, $name, $pdfpath) {
        // $file should include path and filename
        $filename = basename($pdfpath);
        $file_size = filesize($pdfpath);
        $content = chunk_split(base64_encode(file_get_contents($pdfpath))); 
        $uid = md5(uniqid(time()));
        $subject = "New attachment mail: ".$name;
        $subject = "=?UTF-8?B?".base64_encode($subject)."?=";
        $body = "Hello Dude!\n\n"
             ."Testing\n\n"
             ."Testing\n\n\n\n"
             ."Testing\r\n"
             ."Testing\n";
        //combine two headers (attachment mails needs to have specific headers)
        $header .= $this->attachment_headers;
        $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
        $header .= "This is a multi-part message in MIME format.\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-type:text/plain; charset=UTF-8\r\n";
        $header .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
        $header .= $body."\r\n\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
        $header .= "Content-Transfer-Encoding: base64\r\n";
        $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
        $header .= $content."\r\n\r\n";
        $header .= "--".$uid."--"; 

        //( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
        return mail($email, $subject, "", $header);
    }
?>

So, the output with this in my email is following:

Hello Dude!
Testing
Testing
Testing
Testing

So, it does add a new line, but only one, I need to have more. How can I do that?

  • 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-06-18T05:25:15+00:00Added an answer on June 18, 2026 at 5:25 am

    Ok, I can’t find any help from web so I came up with a bubblegum solution. Seems like that for some reason multipart/mixed message strips/removes all additional lines.

     $body = "Hello Dude!\n \n"
                 ."Testing\n \n"
                 ."Testing\n\ n\ \n \n"
                 ."Testing\r \n"
                 ."Testing\n";
    

    See the space between the line break, and the outcome is as it’s supposed to.

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

Sidebar

Related Questions

I'm having problems with a DataTable line, the idea is that I want to
I've been having a few problems running PHP-based utilities within the command line ever
I'm having problems outputting php to javascript when i only output one line javascript
I'm having a problem when running programs that use Java from the command line.
Having problems with the combining of two statements in a controller. Both statements work
I'm having serious problems with the breaks in a Word document generation. this is
The page having problems is... http://schnell.dreamhosters.com/index.php?page=gallery# I use Firebug to debug my jQuery and
I'm having trouble getting my line breaks to show up in a textarea. The
I'm having the same problem explained there except the mysterious line breaks is added
I'm having a problem with this line of sed when i run it from

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.