Breaking News
Loading...

PHP mail with attachment

Share on Google Plus

PHP mail with attachment



<?php
/* Email Detials */
  $mail_to = "<receipient address>";
  $from_mail = "<sender address>";
  $from_name = "<sender name>";
  $reply_to = "<reply-to address>";
  $subject = "<email subject>";
  $message = "<email content>";

/* Attachment File */
  // Attachment location
  $file_name = "1.pdf";
  $path = "images/";
   
  // Read the file content
  $file = $path.$file_name;
  $file_size = filesize($file);
  $handle = fopen($file, "r");
  $content = fread($handle, $file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
   
/* Set the email header */
  // Generate a boundary
  $boundary = md5(uniqid(time()));
   

   
  // Attachment
  // Edit content type for different file extensions
$header.="Content-Type: application/pdf; name=".$file."";  
$header.="Content-Transfer-Encoding: base64 "; 
$header.="Content-Disposition: attachment " 
   
  // Send email
  if (mail($mail_to, $subject, "", $header)) {
    echo "Sent";
  } else {
    echo "Error";
  }
?>

You Might Also Like

0 comments

About me


Like us on Facebook