PHP 直接 SMTP 发送 + 附件

PHP Direct SMTP Send + Attachment

我正在使用 xpertmailer 在 MX 查找后将电子邮件直接发送到远程 SMTP 服务器。这非常有效,适用于旧的封闭源 NAS 驱动器 运行 PHP4 和当前的 PHP5 盒子。

<?php

define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
require_once '/path-to/SMTP.php'; // path to 'SMTP.php' file from XPM4 package

$f = 'me@mydomain.net'; // from mail address
$t = 'client@destination.net'; // to mail address

// standard mail message RFC2822
$m = 'From: '.$f."\r\n".
     'To: '.$t."\r\n".
     'Subject: test'."\r\n".
     'Content-Type: text/plain'."\r\n\r\n".
     'Text message.';

$h = explode('@', $t); // get client hostname
$c = SMTP::MXconnect($h[1]); // connect to SMTP server (direct) from MX hosts list
$s = SMTP::Send($c, array($t), $m, $f); // send mail
// print result
if ($s) echo 'Sent !';
else print_r($_RESULT);
SMTP::Disconnect($c); // disconnect

?>

我现在正在尝试向其中添加附件,但我不知道如何添加和发送附件。

有人知道我该怎么做吗?

谢谢

示例:

$m = new MAIL;

// attach source
$a = $m->Attach('text message', 'text/plain');

$f = '/path/image.gif';
// attach file '$f', disposition 'inline' and give a name 'photo.gif' with ID value (this ID value can be used in embed HTML images)
$a = $m->Attach(file_get_contents($f), FUNC::mime_type($f), 'photo.gif', null, null, 'inline', MIME::unique());

echo $a ? 'attached' : 'error';