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

  • Home
  • SEARCH
  • 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 7748733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:51:36+00:00 2026-06-01T10:51:36+00:00

i have function to send mail with attachment to microsoft exchange server. My problem

  • 0

i have function to send mail with attachment to microsoft exchange server. My problem is that when I wanna to add attachment the whole message part is adding my text to attachment source. When I save attachment to body section of mail, my attachment source is wrote down in email body instead of creating an attachment. Belowe is my source.

$eol = "\r\n";

$boundary = md5(time());

    $mail = "explame@explame.com";  

$headers  = "From: no-replay@explame.com".$eol;
$headers .= "MIME-Version: 1.0".$eol; //utworzenie headera wiadomosci
$headers .= "Content-type: multipart/alternative; charset=utf-8".$eol;
$headers .= "Message-ID:< TheSystem@".$_SERVER['SERVER_NAME'].">".$eol; 
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$boundary."\"".$eol; 
$headers .= "--$boundary".$eol;
$headers .= "Content-Type: text/plain; charset=utf-8".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol;
$headers .= "--$boundary--".$eol.$eol;

if ($file != ''){
    $handle = fopen($file['tmp_name'], 'rb');
    $f_content = fread($handle, $file['size']);
    $attachment =  chunk_split(base64_encode($f_content));
    fclose($handle);

    $content .= "--$boundary".$eol;
    $content .= "Content-type: ".$file['type'].'; '.'name="'.$file['name'].'"'.$eol;
    $content .= 'Content-Disposition: attachment; filename="'.$file['name'].'"'.$eol.$eol;
    $content .= "Content-Transfer-Encoding: base64".$eol;
    $content .= $attachment.$eol.$eol;
    $content .= "--$boundary--".$eol.$eol;

    }
mail($mail, 'title', $content, $headers)

i think I tried everything but nothing works for me. 🙁

  • 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-01T10:51:37+00:00Added an answer on June 1, 2026 at 10:51 am

    a really good PHP lib for sending mail (especially for dealing with attachments) is the phpmailer class.

    You can find it here: http://code.google.com/a/apache-extras.org/p/phpmailer/

    EDIT – the above link is to the old project, it’s now hosted on Github and more regularly maintained: https://github.com/PHPMailer/PHPMailer

    And an example of how to use it to send an attachment:

    include("class.phpmailer.php");
    $mail = new PHPMailer();    
    $mail->IsHTML(true);
    $mail->SetFrom('from@mydomain.com');
    $mail->AddReplyTo('from@mydomain.com'); //set from & reply-to headers
    $mail->AddAddress('to@exchangeserver.com'); //set destination address
    
    $mail->Subject="some subject"; //set subject
    $mail->Body="some body HTML <br/><br/>"; //set body content
    
    $mail->AddAttachment('filepath', 'filename'); //attach file
    
    $mail->AltBody = "Can't see this message? Please view in HTML\n\n";
    $mail->Send();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that uses PHP mail() function to send emails: mail(me@mydomain.com, Subject,
I have used default mail() function to send email it sends emails to yahoo
I have a function that uses CDO to send emails with request to have
I have a class named toto which I send to a function that does
I have a function that accepts a string and generates an email attachment based
I have a function that sends email using asp.net built in mail framework. I've
I have develop a function in PYTHON that sends emails with one .doc attachment
I have a function to send emails the strange thing is that its working
I am just working on a mail function and have problem with formatting it.
I have configured my server to send mail by setting sendmail_path = /usr/sbin/sendmail in

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.