English 中文(简体)
What is wrong with this mail header text?
原标题:

The following $header is being sent via PHP s mail($to,$subject,$content,$header) command. The mail arrives and appears to have an attachment. But the mail text is empty as is the file. I think this has something to do with line spacing but I can t see the problem. I have tried putting the contents (between the boundaries) in $contents rather than appending it to $header. It doesn t make a difference. Any thoughts?

From: dnagirl@someplace.com 
Reply-To: dnagirl@someplace.com 
X-Mailer: PHP 5.3.1
MIME-Version: 1.0
Content-Type: multipart/mixed;
    boundary="7425195ade9d89bc7492cf520bf9f33a"

--7425195ade9d89bc7492cf520bf9f33a
Content-type:text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

this is a test message.

--7425195ade9d89bc7492cf520bf9f33a
Content-Type: application/pdf; name="test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.pdf"

JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k
ZT4+CnN0cmVhbQp4nE2PT0vEMBDFadVdO4p/v8AcUyFjMmma5CqIIF5cctt6WnFBqLD1+4Np1nY3
c3lvfm+GyQ4VaUY11iQ2PTyuHG5/Ibdx9fIvhi3swJMZX24c602PTzENegwUbNAO4xcoCsG5xuWE
.
... the rest of the file
.
MDAwMDA2MDYgMDAwMDAgbiAKMDAwMDAwMDcwNyAwMDAwMCBuIAowMDAwMDAxMDY4IDAwMDAwIG4g
CjAwMDAwMDA2NDcgMDAwMDAgbiAKMDAwMDAwMDY3NyAwMDAwMCBuIAowMDAwMDAxMjg2IDAwMDAw
IG4gCjAwMDAwMDA5MzIgMDAwMDAgbiAKdHJhaWxlcgo8PCAvU2l6ZSAxNCAvUm9vdCAxIDAgUiAv
SW5mbyAyIDAgUgovSUQgWzxEMURDN0E2OUUzN0QzNjI1MDUyMEFFMjU0MTMxNTQwQz48RDFEQzdB
NjlFMzdEMzYyNTA1MjBBRTI1NDEzMTU0MEM+XQo+PgpzdGFydHhyZWYKNDY5MwolJUVPRgo=


--7425195ade9d89bc7492cf520bf9f33a--

$header ends without a line break

最佳回答

I use the code below to send a message with an attachment as well as html and text message parts. I remember fighting with it a long time to get it right, but unfortunately don t remember which parts were my problems. Maybe looking at it will help you out. I ve changed some irrelevant variables and hopefully made it easier to read. Feel free to ask if something is weird or unclear and I ll try to explain.

public function sendEmail($htmlString)
{
    $random_hash = md5(date( r , time()));

    $message = "--mixed-$random_hash
";
    $message .=  Content-Type: multipart/alternative; boundary="alt-  . $random_hash .  "  . "

";
    $message .=  MIME-Version: 1.0  . "
";
    $message .=  --alt-  . $random_hash . "
";
    $message .=  Content-Type: text/plain; charset="iso-8859-1"  . "
";
    $message .=  Content-Transfer-Encoding: 7bit  . "

";

    // text message
    $message .= strip_tags($htmlString) . "

";

    $message .=  --alt-  . $random_hash . "
";
    $message .=  Content-Type: text/html; charset="iso-8859-1"  . "
";
    $message .=  Content-Transfer-Encoding: 7bit  . "

";

    // html message
    $message .= $htmlString . "

";

    $message .=  --alt-  . $random_hash .  --  . "
";

    // graph image
    if($this->selectedGraph != 0)
    {
        $graphString = $this->getGraph(); // image attachment
        $graphString = chunk_split(base64_encode($graphString));

        $linkID =  graph-  . $userInfo[ FirmID ] . $random_hash .  -image ;

        $message .=  --mixed-  . $random_hash . "
";
        $message .=  MIME-Version: 1.0  . "
";
        $message .=  Content-Transfer-Encoding: base64  . "
";
        $message .=  Content-ID:   . $linkID . "
";
        $message .=  Content-Type: image/gif; name="graph.gif"  . "
";
        $message .=  Content-Disposition: attachment  . "

";

        $message .= $graphString;
        $message .=  --mixed-  . $random_hash .  --  . "
";

    }
    else
    {
        $message .=  --mixed-  . $random_hash .  --  . "
";
    }


    $headers =  From:   . $this->from. "
Reply-To: " . $this->replyto;
    $headers .= "
Content-Type: multipart/related; boundary="mixed-" . $random_hash . ""
MIME-Version: 1.0";

    $flags =  -f   . BOUNCED_EMAIL_ADDRESS;

    return mail($userInfo[ Email ], $this->subject, $message, $headers, $flags);

}
问题回答

These things happen when building mime mails from scratch. There are a couple of php modules you can use to generate cool and compatible mime messages. Mail_Mime should do the trick.





相关问题
Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn t seem to work. while(...) { $msg .= "<...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

How to track an email in Java?

How I can track an email? I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

Web Link in a mail is not rendering as link in yahoo

string from = "abc@gmail.com"; string to = "xyz@gmail.com,xyz@yahoo.co.in"; string password="abcxyz"; MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

How to create an email mailing list

Im creating a coming soon page for a website im developing, and im adding an option for the user to enter their email address so we can email them when the site is up. How do I do this?

CCNet email does not include MSBuild results

We re using CCNet 1.4.4.83 but when an MSBuild task fails, we don t get the MSBuild results (i.e. missing file or whatever reason the compile failed) in the email notification. I do see the build ...

热门标签