php 电子邮件脚本不会生成 HTML 版本或附件扩展名。出了什么问题?

发布于 2024-12-29 16:43:49 字数 3160 浏览 0 评论 0原文

这是(全部)代码:

<?php
/*

            WHITE SPACE MATTERS IN THIS DOCUMENT

*/
include("_php/ChromePhp.php");
    // define receiver of email
$to = "[email protected]";
    // define subject of email
$subject = "<--== KABAM!  HTML Email from WR! ==-->";
    // define message to send.  use /n for linebreaks
//$message = 'This is the message.  Read it.  Love it.';
    // create a boundary string.  it must be unique!
$uniqID = md5(date('r', time()));
    // define the headers. separated by \r\n
$headers = "From: some dude" . "\r\n";
$headers .= "Reply-To: nobody" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uniqID."\""."\r\n";
    // read the attachment into a string, encode it and then
    // split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('./_dox/pdftmp/emailTESTER.zip')));
    // define the body of the message
ob_start(); // turn on output buffering
?>
--PHP-mixed-<?php print $uniqID; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php print $uniqID; ?>

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

This is the TEXT email.
Nothing but pure text.  not really fun...

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

<h1>This is the HTML test email.</h1>
<h3>Read it.  Love it.</h3>
<p>this is all HTML.  without any CSS, mind you...</p>

<?php include("_php/formEmail.php"); ?>

--PHP-alt-<?php print $uniqID; ?>--

--PHP-mixed-<?php print $uniqID; ?>
Content-Type: application/zip; name="emailTESTER.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php print $attachment; ?>
--PHP-mixed-<?php print $uniqID; ?>--

<?php
    // copy current buffer contents into $message then delete
    // the contents of the output buffer
$message = ob_get_clean();
    // send the email
$mail_sent = @mail($to, $subject, $message, $headers);
    // display a message depending on mail_sent status
print  $mail_sent ? "Mail Sent: ".$uniqID : "Mail Failed: ".$uniqID;
?>

这就是电子邮件客户端中弹出的内容:(不渲染...)

This is the TEXT email.
Nothing but pure text.  not really fun...

--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h1>This is the HTML test email.</h1>
<h3>Read it.  Love it.</h3>
<p>this is all HTML.  without any CSS, mind you...</p>


--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75--

附件不是“emailTESTER.zip”,而是简单的“第 2 部分”,没有扩展名。如果我添加“.zip”,它就会成为具有正确内容的正确存档(尽管名称错误)...

我三次检查了边界线,我相信它们设置正确。我唯一能想到的就是 Content-Type 声明中的内容...但如果是的话,我对它可能是什么一无所知...我已经阅读了之前关于“PHP email”的所有帖子HTML 等等”虽然它们提供了见解,但没有一个触及我奇怪的问题。 narf

所以。我错过了什么?为什么它不能正确/完全工作?

TIA。

写!

here's (all) the code:

<?php
/*

            WHITE SPACE MATTERS IN THIS DOCUMENT

*/
include("_php/ChromePhp.php");
    // define receiver of email
$to = "[email protected]";
    // define subject of email
$subject = "<--== KABAM!  HTML Email from WR! ==-->";
    // define message to send.  use /n for linebreaks
//$message = 'This is the message.  Read it.  Love it.';
    // create a boundary string.  it must be unique!
$uniqID = md5(date('r', time()));
    // define the headers. separated by \r\n
$headers = "From: some dude" . "\r\n";
$headers .= "Reply-To: nobody" . "\r\n";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uniqID."\""."\r\n";
    // read the attachment into a string, encode it and then
    // split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('./_dox/pdftmp/emailTESTER.zip')));
    // define the body of the message
ob_start(); // turn on output buffering
?>
--PHP-mixed-<?php print $uniqID; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php print $uniqID; ?>

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

This is the TEXT email.
Nothing but pure text.  not really fun...

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

<h1>This is the HTML test email.</h1>
<h3>Read it.  Love it.</h3>
<p>this is all HTML.  without any CSS, mind you...</p>

<?php include("_php/formEmail.php"); ?>

--PHP-alt-<?php print $uniqID; ?>--

--PHP-mixed-<?php print $uniqID; ?>
Content-Type: application/zip; name="emailTESTER.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment

<?php print $attachment; ?>
--PHP-mixed-<?php print $uniqID; ?>--

<?php
    // copy current buffer contents into $message then delete
    // the contents of the output buffer
$message = ob_get_clean();
    // send the email
$mail_sent = @mail($to, $subject, $message, $headers);
    // display a message depending on mail_sent status
print  $mail_sent ? "Mail Sent: ".$uniqID : "Mail Failed: ".$uniqID;
?>

and this is what pops out in the email client: (doesn't render...)

This is the TEXT email.
Nothing but pure text.  not really fun...

--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

<h1>This is the HTML test email.</h1>
<h3>Read it.  Love it.</h3>
<p>this is all HTML.  without any CSS, mind you...</p>


--PHP-alt-a0d18dbf6c6ec8fb30c47adc84234c75--

the attachment, instead of being "emailTESTER.zip" is simply "Part 2" and no extension. if i add '.zip', it becomes the correct archive (albeit misnamed) with the correct contents...

i triple checked the boundary lines, i believe they are correctly set. the only thing that i could think of would be something in the Content-Type declarations...but if it is, i'm blank as to what it might be... i've read all the prior posts on "PHP email HTML blah blah" and while they lent insight, none of them touched on my odd pair of hiccups. narf

so. what did i miss? why is it not working correctly/completely?

TIA.

WR!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2025-01-05 16:43:49

不要重新发明轮子。使用现有的邮件类别。 PHPMailer 非常出色。

Don't reinvent the wheel. Use an existing mail class. PHPMailer is excellent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文