通过上载表格发送包含多个文件链接的电子邮件

时间:2019-03-10 17:28:41

标签: php forms upload

在将多个文件上传到服务器上的目录的表单之后,我想收到一封包含这些文件链接的电子邮件。

我的代码是

...for($x=0; $x < count($_FILES['file']['name']); $x++){
        $file_name = $_FILES['file']['name'][$x];
        $file_size = $_FILES['file']['size'][$x];
        $file_type = $_FILES['file']['type'][$x];
        $tmp_name  = $_FILES['file']['tmp_name'][$x];

        $max_size = 1024 * 20000;
        $type_accepted = array(".zip", "doc", "docx", "pdf", "gif", "png", "jpg", "jpeg");
        $dir = "uploads/";

        if($file_size > $max_size){
            $upload_error = "The file size cannot be bigger than 20MB.";
        }
        elseif(!in_array(pathinfo($file_name, PATHINFO_EXTENSION), $type_accepted)){
            $upload_error = "File missing or invalid.";
        }else{
            move_uploaded_file($tmp_name,$dir.$file_name);
            $upload_error = "File uploaded.";
        }
    }
    if ($name_error == '' and $email_error == '') {
        $to = "[MY_EMAIL]";

        $subject = "From " . $name;

        $message_body = '';
        unset($_POST['submit']);
        $message_body = "Name: " . $name . "\n\n";
        $message_body .= "Email: " . $email . "\n\n";
        $message_body .= "Message: " . $message . "\n\n";
        $message_body .= "Files: [MY_SITE]/uploads/" . $x . "\n\n";

        if (mail($to, $subject, $message_body)){...

谢谢您的帮助!

0 个答案:

没有答案