Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function attachfile($filename, $filedata, $return = false, $reset = false){
- static $attachment = '';
- if($return){
- return $attachment;
- }
- if($reset){
- $attachment = '';
- }
- if($filename != '' && $filedata != ''){
- $filedata = chunk_split(base64_encode($filedata));
- $attachment .= "--{".mime_boundary()."}\n".
- "Content-Type: application/octet-stream; name=\"".($filename)."\"\n".
- "Content-Transfer-Encoding: base64\n".
- "Content-Disposition: attachment; filename=\"".($filename)."\"\n\n".$filedata."\n\n";
- }
- }
- function mime_boundary(){
- static $mb = '';
- if($mb == ''){
- $mb = "==Multipart_Boundary_x".md5(uniqid(time()))."x";
- }
- return $mb;
- }
- /**
- * before calling this function call attachfile function with required inputs and then call send mail the mail will be sent with attachments.
- *
- * @param mixed $to
- * @param mixed $subject
- * @param mixed $msg
- * @param mixed $sender
- * @param mixed $sendername
- * @return mixed
- */
- function sendmail($to, $subject, $msg, $sender = '[email protected]', $sendername = 'Sample Sender Name'){
- global $db;
- $from = $sendername." <".$sender.">";
- $headers = "From: ".$from;
- $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{".mime_boundary()."}\"";
- $message = "--{".mime_boundary()."}\n";
- $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 7bit\n\n";
- $message .= '<html><body>'.$msg."</body></html>\n\n";
- $message .= attachfile('', '', true);
- $message .= "--{".mime_boundary()."}--";
- $returnpath = "-f".$sender;
- if(mail($to, $subject, $message, $headers, $returnpath)){
- return 'Mail Sent';
- }else{
- return 'Mail not accepted by Server';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment