使用phpMailer和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()要发送电子邮件: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从表格上附上电子邮件,并发送。控件之后保存文件的问题。process.php脚本是通过电子邮件发送的。我知道我需要补充AddAttachment();在某个地方(我假设在Body(行)发送附件。但是.。我把什么放在顶部process.php文件要拉进文件uploaded_file?就像某种东西$_FILES['uploaded_file']从Contact-us.php页面中提取文件?里面有什么AddAttachment();对于随电子邮件一起附上和发送的文件,这段代码需要去哪里?请帮助并提供密码!谢谢!
3 回答
米脂
TA贡献1836条经验 获得超3个赞
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) { $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'], $_FILES['uploaded_file']['name']);}
AddAttachment
public function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream')
牛魔王的故事
TA贡献1830条经验 获得超3个赞
无法从客户端PC附加文件(上传)
<form id="form1" name="form1" method="post" action="form_phpm_mailer.php" enctype="multipart/form-data">
慕森卡
TA贡献1806条经验 获得超8个赞
$_FILES['uploaded_file']['tmp_name']
if ($_FILES['uploaded_file']['error'] === UPLOAD_ERR_OK) { ... attach file to email ...}
- 3 回答
- 0 关注
- 554 浏览
添加回答
举报
0/150
提交
取消