php:电子邮件发送失败,并带有多个附件

编程入门 行业动态 更新时间:2024-10-27 13:28:25
本文介绍了php:电子邮件发送失败,并带有多个附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在php中实现邮件功能,它可以通过单个附件正常工作,但是问题是当我尝试发送多个附件时,它无法正常工作。我正在使用php mail()函数发送电子邮件,我试图附加PDF和图像文件。如果附有PDF,则不会附加图片;如果附有PDF,则不会附加PDF。有什么想法我做错了吗?

I am trying to implement mail functionality in php, its working fine with single attachment, but problem is when I am trying to send more than one attachment, its not working. I am using php mail() function for sending emails, I am trying to attach a PDF and an Image file. If PDF attach then Image won't attach, if Image attach then PDF won't attach. Any thoughts where I'm doing wrong?

$header .= 'From: test <noreply@test.ae>' . "\r\n"; $header .= "MIME-Version: 1.0\r\n"; $file = '1.png' $displayname = '1.png'; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); $uid = md5(uniqid(time())); $name = basename($file); $filepdf = '1.pdf' $displaynamepdf= '1.pdf'; $file_sizepdf = filesize($filepdf); $handlepdf = fopen($filepdf, "r"); $contentpdf = fread($handlepdf, $file_sizepdf); fclose($handlepdf); $contentpdf = chunk_split(base64_encode($contentpdf)); $name = basename($file); $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n"; $header .= "--".$uid."\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$displayname."\"\r\n"; // use different content types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$displayname."\"\r\n\r\n"; $header .= $content."\r\n\r\n"; $header .= "Content-Type: application/octet-stream; name=\"".$displaynamepdf."\"\r\n"; // use different contentpdf types here $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$displaynamepdf."\"\r\n\r\n"; $header .= $contentpdf."\r\n\r\n"; $header .= "--".$uid."--"; if (mail($to, $subject, "", $header)) { return 'sent'; } else { return 'not sent'; }

推荐答案

PHPMailer 是电子邮件的最佳选择。

PHPMailer is the best to use for email.

签出一些下面的链接,这些链接将来也会对您有帮助:

checkout some below links which will help you in future also:

  • 使用PHPMailer的PHP邮件中的文件附件
  • php邮件附件
  • 使用phpMailer的附件
  • PHPMailer教程
  • 一个简单的示例:使用 Phpmailer发送带有附件的电子邮件
  • PHP使用PHPMailer和SMTP 发送带有多个附件的电子邮件身份验证
  • 使用PHP发送带有多个附件的电子邮件
  • File Attachments in PHP Mail with PHPMailer
  • php mailer attachments
  • attachments using phpMailer
  • PHPMailer Tutorial
  • A Simple Example : Sending Email with Attachment Using Phpmailer
  • PHP send email with multiple attachments with PHPMailer with SMTP Authentication
  • Sending email with multiple attachments with PHP
  • 这可能会对您有所帮助。

    may this help you.

    更多推荐

    php:电子邮件发送失败,并带有多个附件

    本文发布于:2023-05-27 19:32:49,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/300558.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:词库加载错误:Could not find file &#039;D:\淘小白 高铁采集器win10\Configuration\Dict_Sto

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!