使用PHP mail()函数发送URL附件

使用PHP mail()函数发送URL附件,php,Php,我通过上传发送附件,但现在我想知道我们是否可以仅使用文件的URL发送附件 就像我添加了,我需要将它作为附件发送,而不是作为消息中的内联链接发送到正文中 目前,我正在使用以下代码: HTML: 提交 PHP: 谢谢当然,请使用并验证它。可能需要在某个文件夹中添加文件以发送URLemail@AmitGupta是的,我在服务器上有一个文件夹,其中有文件,我将从该文件夹中获取url。是的,然后只需在HTML电子邮件中添加图像url。 <form method="post" action="

我通过上传
发送附件,但现在我想知道我们是否可以仅使用文件的
URL
发送附件

就像我添加了
,我需要将它作为附件发送,而不是作为消息中的内联链接发送到正文中

目前,我正在使用以下代码:

HTML:


提交
PHP:



谢谢

当然,请使用
并验证它。可能需要在某个文件夹中添加文件以发送URLemail@AmitGupta是的,我在服务器上有一个文件夹,其中有文件,我将从该文件夹中获取url。是的,然后只需在HTML电子邮件中添加图像url。
<form method="post" action="code.php" enctype="multipart/form-data">
    <input type="file" name="file[]" multiple="multiiple" />
    <button type="submit">Submit</button>
</form>
<?php

    foreach(array_combine($_FILES['file']['tmp_name'], $_FILES['file']['name']) as $tmp_name => $file_name ) {
        $filetmp[] = $tmp_name;
        $filename[] = $file_name;
    }

    // email fields: to, from, subject, and so on
    $to = "receiver_email";
    $from = "sender_email"; 
    $subject ="My subject"; 
    $message = "My message";
    $headers = "From: $from";

    // boundary 
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

    // headers for attachment 
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

    // multipart boundary 
    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
    $message .= "--{$mime_boundary}\n";

    // preparing attachments
    for($x=0;$x<count($filetmp);$x++){
        $file = fopen($filetmp[$x],"rb");
        $data = fread($file,filesize($filetmp[$x]));
        fclose($file);
        $data = chunk_split(base64_encode($data));
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$filename[$x]\"\n" . 
        "Content-Disposition: attachment;\n" . " filename=\"$filename[$x]\"\n" . 
        "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
        $message .= "--{$mime_boundary}\n";
    }

    mail($to, $subject, $message, $headers);

?>