【问题标题】:PHP Email Header multiple Attachments [duplicate]PHP电子邮件标题多个附件[重复]
【发布时间】:2017-10-14 01:45:01
【问题描述】:

我正在尝试使用 PHP 的内置 mail() 函数发送一封电子邮件,但我不知道如何在这封邮件中发送两个附件。我已经可以在我的邮件中发送纯文本、Html 文本和一个附件,但它无法发送另一个。

我确定我的邮件头中的任何内容都是错误的,但我不知道是什么。 这是我生成电子邮件的 PHP 代码:

$attachment = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/smalllogo.png')));
$attachment2 = chunk_split(base64_encode(file_get_contents('/var/www/html/style/img/header.png')));
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<?php echo $txtMailPlain;?>

--PHP-alt-<?php echo $random_hash; ?> 
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<?php echo $txtMailHtml;?>

--PHP-alt-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: image/png; name="smalllogo.png" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
X-Attackment-Id: 1

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--

--PHP-mixed-<?php echo $random_hash; ?> 
Content-Type: image/png; name="smalsllogo.png" 
Content-Transfer-Encoding: base64 
Content-Disposition: attachment 
X-Attackment-Id: 2

<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--


<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed"; 

我得到了第一个附件,名为“smalllogo.png”,但我没有得到另一个。而且我不确定我是否收到了正确的纯文本消息。

提前致谢, J. Doe ;)

【问题讨论】:

    标签: php email email-attachments email-headers


    【解决方案1】:

    你在这两个地方都写过

    <?php echo $attachment; ?>
    

    你必须写一个地方是&lt;?php echo $attachment2; ?&gt;

    【讨论】:

    • 通常它应该在同一个附件中,实际上是另一个名称。但我试图改变它,它也没有工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-12
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多