class AttachmentMail {
private $from = '[email protected]';
private $from_name = 'Your Name';
private $reply_to = '[email protected]';
private $to = '';
private $subject = '';
private $message = '';
private $attachment = '';
private $attachment_filename = '';
public function __construct($to, $subject, $message, $attachment = '', $attachment_filename = '') {
$this -> to = $to;
$this -> subject = $subject;
$this -> message = $message;
$this -> attachment = $attachment;
$this -> attachment_filename = $attachment_filename;
}
public function mail() {
if (!empty($this -> attachment)) {
$filename = empty($this -> attachment_filename) ? basename($this -> attachment) : $this -> attachment_filename ;
$path = dirname($this -> attachment);
$mailto = $this -> to;
$from_mail = $this -> from;
$from_name = $this -> from_name;
$replyto = $this -> reply_to;
$subject = $this -> subject;
$message = $this -> message;
$file = $path.'/'.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$header = "From: ".$from_name." <".$from_mail."> ";
$header .= "Reply-To: ".$replyto." ";
$header .= "MIME-Version: 1.0 ";
$header .= "Content-Type: multipart/mixed; boundary="".$uid."" ";
$header .= "This is a multi-part message in MIME format. ";
$header .= "--".$uid." ";
$header .= "Content-type:text/plain; charset=iso-8859-1 ";
$header .= "Content-Transfer-Encoding: 7bit ";
$header .= $message." ";
$header .= "--".$uid." ";
$header .= "Content-Type: application/octet-stream; name="".$filename."" "; // use diff. tyoes here
$header .= "Content-Transfer-Encoding: base64 ";
$header .= "Content-Disposition: attachment; filename="".$filename."" ";
$header .= $content." ";
$header .= "--".$uid."--";
if (mail($mailto, $subject, "", $header)) {
return true;
} else {
return false;
}
} else {
$header = "From: ".($this -> from_name)." <".($this -> from)."> ";
$header .= "Reply-To: ".($this -> reply_to)." ";
if (mail($this -> to, $this -> subject, $this -> message, $header)) {
return true;
} else {
return false;
}
}
}
}
?>
调用方法
require ('Email-Attachment.php');
$sendit = new AttachmentEmail('[email protected]', 'Merry Christmas!', 'Hi', '/home/racker/gift.jpg');
$sendit -> mail();
?>
我的博物馆故事 官方安卓版v1.61.2
我的博物馆故事是一款以消除为主题的经营养成类手游,在这里玩家
专业模拟飞行10 手机版v12.2.4
专业模拟飞行10安卓版是一款飞行休闲手游,顶尖的物理飞行引擎
动物起义战斗模拟器二琳同款 最新版v4.1.1
动物起义战斗模拟器是一个非常有趣的模拟类游戏,玩家可以召唤各
迷你世界七周年 安卓手机版v1.43.0
迷你世界7周年是一款由《迷你世界》官方推出的庆祝特别版本,在
劫后公司无限资源版 v1.0.5.1
劫后公司内置菜单版是游戏的破解版本,在该版本中为玩家提供了内