【问题标题】:How to attach two files in one email with my PHP Code? [duplicate]如何使用我的 PHP 代码在一封电子邮件中附加两个文件? [复制]
【发布时间】:2017-03-04 14:33:28
【问题描述】:

我正在尝试将两个文件附加到一封电子邮件中(请参阅下面的代码),但我在收到的电子邮件中只收到其中一个。

if(isset($_POST['submits']))
{
    //The form has been submitted, prep a nice thank you message
    $output = '<h1>Thanks for your file and message!</h1>';
    //Set the form flag to no display (cheap way!)
    $flags = 'style="display:none;"';

    //Deal with the email
    $to = 'info@domain.org';
    $subject = 'cv and image upload';

    $message = strip_tags($_POST['message']);
    $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
    $filename = $_FILES['file']['name'];

    $boundary =md5(date('r', time())); 

    $headers = "From: info@domain.org\r\nReply-To: info@domain.org";
    $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";

    $message="This is a multi-part message in MIME format.--_1_$boundaryContent-Type: multipart/alternative; boundary=\"_2_$boundary\"--_2_$boundaryContent-Type: text/plain; charset=\"iso-8859-1\"Content-Transfer-Encoding: 7bit$message--_2_$boundary----_1_$boundaryContent-Type: application/octet-stream; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment--_1_$boundary--";

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

【问题讨论】:

  • 尝试 Php Swiftmailer 或 Phpmailer。这些将很容易配置和发送多个附件

标签: php email email-attachments


【解决方案1】:

尝试使用 javascript 向表单添加更多具有不同名称的文件输入。或者如果 ui 不重要,您可以使用更多输入。 您不能一次从同一输入上传两个文件。 最后使用 smtp insted of mail()。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-18
    • 2015-09-24
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    相关资源
    最近更新 更多