很可能與你列出的所有3個庫(PHPMailer的,PEAR和Swiftmailer)做。
對於PHPMailer的,你可以看到一個tutorial here:
require_once '../class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo "Message Sent OK<P></P>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
AddAttachment將文件從您的服務器。
如何從HTML表單上傳文件可以是found here。發送郵件後,您可以從服務器上刪除(unlink)該文件。
PHP manual can help you更好地低於和上傳文件。
所有你想要做的事情都很容易實現,但是解釋的時間比做的要長:)但是,我給你的所有鏈接都有你需要的一切。如果您有具體問題,請告訴我。
對於上面提到的其他解決方案之一,您可能會問得更多。讓這些工作比試圖推出自己的解決方案要容易得多。事實是文件附件並不那麼簡單。 – Cfreak 2010-07-10 21:08:35