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

x
  • 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.

<?php
      $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);
      fclose($handle);

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

      $mime_boundary=md5(time());

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

      //Attachment
      $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;

      //Finished
      $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
0
cemplukcute2003
Asked:
cemplukcute2003
  • 2
  • 2
  • 2
1 Solution
 
ahoffmannCommented:
> 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?
0
 
cemplukcute2003Author Commented:
The .uoreg files :)
I can download it, but my software can't open it.
0
 
ahoffmannCommented:
> .. download ..
and what has this to do with mail and/or your php script?
0
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!

 
dragoman_it_supportCommented:
Why not try PHPMailer?  http://phpmailer.sourceforge.net/
0
 
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
0
 
dragoman_it_supportCommented:
Know what you mean!
Glad it all worked.
0

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