PHP发送邮件附件 [英] PHP sending mail attachments
本文介绍了PHP发送邮件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现发布关于向邮件添加附件。问题是如何连接上传的文件与该功能?我必须通过什么?
I found the post about adding attachments to the mail. The question is how to connect uploaded file with that function? What I have to pass?
UPD:
echo '<pre>';
print_r($_FILES);
echo '</pre>';
$uploads_dir = '/uploads'; // It has need rights
$tmp_name = $_FILES["vac_file"]["tmp_name"];
$res = is_uploaded_file($tmp_name); // This is true
$name = $_FILES["vac_file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
echo '$tmp_name: '. $tmp_name . '; $name: ' . $name;
→
Array
(
[vac_file] => Array
(
[name] => LFS.desktop
[type] => application/octet-stream
[tmp_name] => /tmp/phpV417nF
[error] => 0
[size] => 226
)
)
yeah!
Warning: move_uploaded_file(/uploads/LFS.desktop): failed to open stream: No such file or directory in /srv/http/vacancies_attachment.php on line 47 Warning: move_uploaded_file(): Unable to move '/tmp/phpV417nF' to '/uploads/LFS.desktop' in /srv/http/vacancies_attachment.php on line 47 $tmp_name: /tmp/phpV417nF; $name: LFS.desktop
推荐答案
使用 move_uploaded_file()
将文件移动到临时位置;将其附加到邮件,然后将其删除(或保留,无论您想要做什么)。
Use move_uploaded_file()
to move the file to a temporary location; attach it to the mail from there and delete it afterwards (or keep it, whatever you want to do).
请参阅文件上传的PHP手册,详细的例子。
这篇关于PHP发送邮件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文