这是我的第一篇文章,我希望能在我的 phpMailer 联系表单中添加附件字段方面获得一些帮助。我已经在 html 网站中添加了一个上传器 [browse] 栏,但我不知道如何将它与 phpmailer 链接。我必须在 phpmailer.php 包中声明它还是用它做些什么?
我真的很感激一些帮助。下面是我绝望的尝试。
代码片段:
<?
$body = ob_get_contents();
$to = 'xxx@xxxx.com>';
$email = $email;
$subject = $subject;
$fromaddress = "xxx@xxxx.com";
$fromname = "Online Contact";
require("phpmailer.php"); //<<this is the original pack
$mail = new PHPMailer();
$mail->From = "xxx@xxxx.com";
$mail->FromName = "My Name";
$mail->AddBCC("xxx@xxxx.com","Name 1");
$mail->AddAddress( $email,"Name 2");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
// attachment
$mail->AddAttachment('uploadbar', 'new_file.pdf'); // the name of my html uploader is uploadbar, clicking browse to locate a file
if(!$mail->Send()) {
$recipient = 'xxx@xxxx.com';
$subject = 'Contact form failed';
$content = $body;
mail($recipient, $subject, $content, "From: xxx@xxxx.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
?>