php邮件附件 - 错误 - 如何调试

时间:2015-06-01 15:48:42

标签: php email csv email-attachments

我搜索并尝试不同的方法来生成带附件的php邮件,可以使用客户端(Outlook)进行保存。它没有工作,我不知道为什么?

如果脚本使用以下代码发送邮件:

    $result  = mail($mail_to, $subject, $headers);

我收到了一封内嵌base64编码附件的电子邮件,如果以这种方式使用它:

    $result  = mail($mail_to, $subject, "", $headers); 

    $result  = mail($mail_to, $subject, $text, $headers); 

我收到了PHP错误:" false" - 邮件无法发送。

所以它不是和Mailserverproblem,我认为并且从headerview我认为它应该工作,我在Linux网站上没有收到邮件错误。

来自附件内联邮件的一部分:

    MIME-Version: 1.0
    From: user@nowhere.xyz
    Content-Type: multipart/mixed; boundary="F34A3E8D822EE5A70EEDE9C3C143243C"

    --F34A3E8D822EE5A70EEDE9C3C143243C
    Content-Type: multipart/alternative; boundary="A0403290562B2A2F19FB62E48C51BE33"

    --A0403290562B2A2F19FB62E48C51BE33
    Content-Type: text/plain
    Content-Transfer-Encoding: 8bit

    Hello Mr. Xyz,
    Some stupid text as an example.

    --A0403290562B2A2F19FB62E48C51BE33--

    --F34A3E8D822EE5A70EEDE9C3C143243C
    Content-Type: application/CSV; charset="ISO-8859-1"; name="trouble.csv"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename="trouble.csv"

    ...
    YWNodW5nIG5pY2h0IGVyZm9yZGVybGljaCAvIG3DtmdsaWNoIjsiIjsiIjsK

    --F34A3E8D822EE5A70EEDE9C3C143243C--

匹配的PHP代码:

$text = "Hello Mr. Xyz," . $nl . "Some stupid text as an example." . $nl; $content = chunk_split(base64_encode($file)); $headers = "MIME-Version: 1.0" . $nl; $headers .= "From: " . $mail_from . $nl; $headers .= "Content-Type: multipart/mixed; boundary=\"" . $boundary1 . "\"" . $nl . $nl; $headers .= "--" . $boundary1 . $nl; $headers .= "Content-Type: multipart/alternative; boundary=\"" . $boundary2 . "\"" . $nl . $nl; $headers .= "--" . $boundary2 . $nl; $headers .= "Content-Type: text/plain" . $nl; $headers .= "Content-Transfer-Encoding: 8bit" . $nl . $nl; $headers .= $text . $nl; $headers .= "--" . $boundary2 . "--" . $nl . $nl; $headers .= "--" . $boundary1 . $nl . $nl; $headers .= "Content-Type: application/excel; charset=\"ISO-8859-1\"; name=\"xyz.csv\"" . $nl; $headers .= "Content-Transfer-Encoding: base64" . $nl; $headers .= "Content-Disposition: attachment; filename=\"xyz.csv\"" . $nl . $nl; $headers .= $content . $nl; $headers .= "--" . $boundary1 . "--" . $nl;

那么,bug在哪里?我该如何调试这种情况? Thx提前......

1 个答案:

答案 0 :(得分:0)

这个有用......

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="56dp">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        card_view:cardCornerRadius="2dp"
        card_view:cardBackgroundColor="@android:color/white"
        card_view:cardElevation="2.5dp"
        card_view:cardPreventCornerOverlap="true"
        card_view:cardUseCompatPadding="true"
        android:visibility="invisible" /> <!-- this -->

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="48dp"
        android:layout_gravity="center_vertical"
        android:textColor="@color/black"
        android:text="@string/dummy_title" />
</FrameLayout>

......带着一个小虫子。我有一个额外的感觉,但现在好了。我们还有一个更长的玩法是&#34; \ n&#34;,&#34; \ r \ n&#34;以及两者在正确位置(线)的混合。