[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

PHP Mail Attachment

Hi, i want to create a code in PHP for sending email with an attachment.
I will attach a license file with my own extension, i.e uoreg files.

      $user = $_SESSION["username"];
        $licenseName = $user."license.uoreg";
      $location = "./license/".$licenseName;
      $eol = "\n";

      $handle = fopen($location, "rb");
      $contents = fread($handle, filesize($location));
      $contents = chunk_split(base64_encode($contents));
      $fType = filetype($location);

      $emailAddr = "testing@yahoo.com";
      $subject = "License file";


      $headers = 'MIME-Version: 1.0'.$eol;
      $headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
      $msg = "";

      $msg = "--".$mime_boundary.$eol;
      $msg .= "Content-Type: application/octet-stream; name=\"".$licenseName."\"".$eol;
      $msg .= "Content-Transfer-Encoding: base64".$eol;
      $msg .= "Content-Disposition: attachment; filename=\"".$licenseName."\"".$eol.$eol;
      $msg .= $contents.$eol.$eol;

      //Setup for text OR html
      $msg .= "Content-Type: multipart/alternative".$eol;

      $msg .= "--".$mime_boundary."--".$eol.$eol;

      $ok = mail($emailAddr, $subject, $msg, $headers);

I manage to download a file, but when i try to open up the files with our software.
Our software can't read the files. Though I already open and read the files.
Can someone help me, pls?
Thanks in advance
  • 2
  • 2
  • 2
1 Solution
> I manage to download a file, but when i try to open up the files with our software.
hmm, which files are you talking about?
cemplukcute2003Author Commented:
The .uoreg files :)
I can download it, but my software can't open it.
> .. download ..
and what has this to do with mail and/or your php script?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Why not try PHPMailer?  http://phpmailer.sourceforge.net/
cemplukcute2003Author Commented:
Yea, thanks dragonman. PHPMailer works just nice :D
Sorry for the late reply, i was busy with final year project...:(
Well, i think you know how's student's life :p
Know what you mean!
Glad it all worked.

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now