【问题标题】:How to attach HTML file to email using content taken from DB in PHP?如何使用从 PHP 中获取的内容将 HTML 文件附加到电子邮件?
【发布时间】:2008-11-03 19:15:49
【问题描述】:

如何通过 PHP 发送带有 HTML 文件附件的邮件? -> HTML 文件(代码)的内容在 DB 中的字符串中。有一些简单的方法或免费脚本可以做到这一点吗?我不想在本地存储文件,我需要从数据库中读取它并作为附件直接发送(不包含在正文中)。

【问题讨论】:

    标签: php html database email attachment


    【解决方案1】:

    如果您很难正确设置标题,您可以随时使用 PHP Mailer 之类的东西,而不是重新发明轮子。

    【讨论】:

      【解决方案2】:

      我喜欢梨。

      <?
      include('Mail.php');
      include('Mail/mime.php');
      $text = 'Text version of email';
      $html = '<html><body>HTML version of email</body></html>';
      $file = './files/example.zip';
      $crlf = "rn";
      $hdrs = array(
                    'From'    => 'someone@domain.pl',
                    'To'      => 'someone@domain.pl',
                    'Subject' => 'Test mime message'
                    );
      $mime = new Mail_mime($crlf);
      $mime->setTXTBody($text);
      $mime->setHTMLBody($html);
      $mime->addAttachment($file,'application/octet-stream');
      $body = $mime->get();
      $hdrs = $mime->headers($hdrs);
      $mail =& Mail::factory('mail', $params);
      $mail->send('mail@domain.pl', $hdrs, $body); 
      ?>
      

      【讨论】:

        【解决方案3】:

        您应该可以关注these instructions 发送电子邮件附件。您只需调整代码以从数据库中读取字符串,而不是读取文件的内容。

        【讨论】:

          猜你喜欢
          • 2020-03-18
          • 2010-12-07
          • 2012-12-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2010-12-09
          • 1970-01-01
          • 2020-08-20
          相关资源
          最近更新 更多