Send email attachment php

This tutorial explains how to send email attachment php. The function reads the data from the upload file from the form on submissions and send the file as email attachment.

Please check the php tutorial that explains how to send the upload file as attachment and also send all files in a folder as attachment.

function pepareAttachment( $filename ,$fileorgname) {
    $attachContent = '';
    $file = fopen($filename,"rb");
    $data = fread($file,filesize($filename));
    fclose($file);
    $cvData = chunk_split(base64_encode($data));
    $attachContent .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$fileorgname\"\n" . 
    "Content-Disposition: attachment;\n" . " filename=\"$fileorgname\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . $cvData . "\n\n";
    $attachContent .= "--{$mime_boundary}\n"; 
    return $attachContent;
    
}

Share this Tutorial