如何在梨邮件中包含php html文件 [英] how to include php html file in PEAR mail

查看:60
本文介绍了如何在梨邮件中包含php html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于发送新闻通讯的php文件.最近,我搬到了新服务器上,他们使用PEAR Mail而不是默认的PHP邮件发送邮件,因此我不得不更新脚本以使其正常运行.但是它仍然无法正常工作.我得到的是TXT版本而不是HTML版本.

I have a php file that I use to send newsletters. Recently I moved to a new server and they use PEAR Mail instead of the default PHP mail to send mails and I had to update my script to function. But it's still not working. I get the TXT version not the HTML version.

如果我在setHTMLBody()中手动输入html代码,它将起作用,但是当我将其替换为ob_start $ output_string 变量时,它将不起作用.

If I manually enter the html codes inside the setHTMLBody() it works but when I replace it with my ob_start $output_string variable it doesn't work.

这是我的剧本;

ob_start();
include "URL/To/File.php";
$output_string = ob_get_contents();
ob_end_clean();

$headers['From'] = 'from@email.com';
$headers['Subject'] = 'Newsletter Subject';

require_once('Mail.php');
require_once('Mail/mime.php');

$message = new Mail_mime();
$message->setTXTBody("Your client doesn't support HTML.");

$message->setHTMLBody(''.$output_string.'');

$mail =& Mail::factory('mail');

$result = $mail->send('myemailaddress@gmail.com', $message->headers($headers), $message->get());

if (PEAR::isError($result)) {
echo("<span>" . $result->getMessage() . "</span>");
} else {
echo("<span style='color: #f7941c; font-weight: bold'>Congratulations! 
Your mail has been sent successfully</span>");
}

如何正确正确地输入下面的行?它现在无法正常工作.

how do I correctly input the line below correctly? It's not working as is right now.

$message->setHTMLBody(''.$output_string.'');

推荐答案

所以我现在对这个问题(在移动设备上工作)很冷,尽管让我们看看能否为您提供帮助.因此,我查找了 setHTMLBody函数.期望参数 应该是 type 有点模糊.在PHP中,您可以使用 gettype($ example)获得类型(如JavaScript中的 console.log(typeof example); ),尽管PHP通常对类型更为宽容(计算a具有字符串类型的数字将在PHP中起作用,而不在JavaScript中起作用).

So I'm cold on this subject right now (working on mobile) though let's see if I can help you out. So I looked up the setHTMLBody function. It's a little fuzzy on the type that the expected parameters should be. In PHP you can get the type using gettype($example) (like console.log(typeof example); in JavaScript though PHP is generally more forgiving about types (calculating a number that has a string type will work in PHP, not JavaScript)).

该函数的名称暗示它应该应该成为电子邮件HTML的一部分.现在,在我基于Web平台的电子邮件中构建的所有模块中,最具挑战性的不是因为它固有的复杂性,而是因为它非常主观.在示例中,某些服务器可能希望您提供< html> 元素,而其他服务器则希望提供< body> 元素,而其他服务器则不在乎是否忽略它(而我我不确定如果有任何规范在这里声明什么是正确的").我没有刻意地压缩电子邮件中的数据(尽管此时技术方面的信息丢失了,但只是在Web邮件中输出).长话直说:客户的用户代理(浏览器,电子邮件应用程序等)应该处理压缩,而不是您.

The name of the function implies that it should make this part of the email HTML. Now of all the modules I've built on my web platform email has been the most challenging not because it's inherently complex though because it's very subjective. In example some servers might expect you to serve an <html> element, others a <body> element and others won't care if you omit it (and I'm not sure what if any specifications declare what is "proper" here). I've not intentionally worked with compressing data in emails (just output in web mail though it's technical context is lost at that point). Long story straight here: the client's user agent (browser, email application, etc) should be handling the compression, not you.

PHP ob的东西有点令人费解.我不喜欢将相同的函数/方法用于压缩,并且能够在将输出发送到客户端之前捕获并进行查找/替换输出.我认为您正在使用它进行压缩,尽管无论出于何种原因,您也可能会使用它来替换部分代码.在这种情况下,进行故障排除的最佳选择(假设您的ob应该工作,很可能是替换代码位)是使用字符串并在此环境之外对其进行测试.当我测试cron作业时,我总是先在正常环境中测试它们(尽管请记住,cron作业在更为有限的环境中运行,因此在这里进行调试时,我只有 print_r($ _ SERVER)通过电子邮件向我发送信息.

PHP ob stuff is a bit convoluted. I dislike the same function/method being used for both compression and being able to capture and do find/replace with the output before sending it to a client. I think you're using it for compression though you could also be using it to replace bits of code for whatever reason. In this case your best bet for troubleshooting (presuming that your ob should work, most likely for replacing bits of code) is to use the string and test it outside of this environment. When I test cron jobs I always test them in normal environments first (though keep in mind cron jobs run in a much more limited environment so for debugging there I just have print_r($_SERVER) send me information via email).

所以我认为您的ob代码弄乱了解析器 setHTMLBody()函数.分解代码,直到有可用的位,然后然后向其中添加必要的和越来越复杂的位,直到遇到问题为止,然后因为您确切地知道刚刚添加的内容,因此可以单挑这个问题要容易得多.

So I think your ob code is messing up the parser setHTMLBody() function. Break your code down until you have working bits and then add your necessary and increasingly complex bits to it until you hit a problem and then because you know exactly what you just added you'll be able to single out the issue much easier.

我需要进一步澄清,尽管我稍后可以编辑此答案.让我知道您的位置,即使需要一天的时间,我也会始终检查通知.

I'd need further clarification though I can edit this answer later. Let me know where you're at, I always check notifications even if it takes a day.

我在开发时会使用一些十二个工具.我不确定该工具是否可以验证,尽管它可能会以某种方式帮助您,因为您正在使用电子邮件. https://www.mail-tester.com/帮助我解决了一些与电子邮件有关的问题(与该问题无关).

I have a few dozen tools that I use when I develop. I'm not sure if this tool will validate though it may help you somehow since you are working on email. https://www.mail-tester.com/ helped me address some issues related to email (it's not related to this issue).

这篇关于如何在梨邮件中包含php html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆