我有一个example.com/contact-us.php看起来像这样的表格(简化):
example.com/contact-us.php
<form method="post" action="process.php" enctype="multipart/form-data"> <input type="file" name="uploaded_file" id="uploaded_file" /> <input type="hidden" name="MAX_FILE_SIZE" value="10000000" /> </form>
在我的process.php文件中,我使用以下代码PHPMailer()来发送电子邮件:
process.php
PHPMailer()
require("phpmailer.php"); $mail = new PHPMailer(); $mail->From = me@example.com; $mail->FromName = My name; $mail->AddAddress(me@example.com,"John Doe"); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Subject = "Contact Form Submitted"; $mail->Body = "This is the body of the message.";
电子邮件正确发送了正文,但没有附件uploaded_file。
uploaded_file
我的问题
我需要将uploaded_file表单中的文件附加到电子邮件中并发送出去。process.php脚本通过电子邮件发送文件后,我不在乎保存文件。
我知道我需要在AddAttachment();某处(我假设在此Body行下)添加附件以进行发送。但…
AddAttachment();
Body
$_FILES['uploaded_file']
请帮助并提供代码!谢谢!
尝试:
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) { $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'], $_FILES['uploaded_file']['name']); }
基本示例也可以在找到。
函数定义为AddAttachment:
AddAttachment
public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream')