我不完全是一个亲,所以请原谅我问这样一个(可能)愚蠢的问题。浏览到图像文件,然后附加到PHP邮件
我需要帮助设置(在html页面上)一种方法,允许访问者浏览到计算机上的文件(实际上是2个文件),当他们选择提交时,该文件将附加到PHP邮件表单。
我知道PHP邮件图像,我需要使用像PearMime或PHPMailer。
* 更新 *
好了,现在我知道如何把HTML表单来获取文件。当我使用下面的PHP时,我做错了什么?我有两个通过ID从HTML页面请求的文件(HTML同时创建了这两个文件),也就是PHPMailer_5.2.1的位置,$ mail-> MsgHTML(file_get_contents('testfiles.html'));实际上是查看我在该位置创建的html页面,该页面仅包含正文中包含单词Sample的html文档的模板启动器。
<?php
require("PHPMailer_5.2.1/class.phpmailer.php");
$mail = new PHPMailer(); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
$file1 = $_REQUEST['file1'];
$file2 = $_REQUEST['file2'];
try {
$mail->AddReplyTo('[email protected]', 'FirstName LastName');
$mail->AddAddress('[email protected]', 'FirstName LastName');
$mail->SetFrom('[email protected]', 'FirstName LastName');
$mail->AddReplyTo('[email protected]', 'FirstName LastName');
$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('testfiles.html'));
$mail->AddAttachment($file1); // attachment
$mail->AddAttachment($file2); // attachment
$mail->Send();
echo "Message Sent OK</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!
}
?>
我很困惑,这条线有什么问题:'$ mail-> MsgHTML(file_get_contents('testfiles.html'));'你想用它做什么不能正常工作? – MasterGberry 2012-07-27 23:07:18