【问题标题】:Generating HTML documents in PHP在 PHP 中生成 HTML 文档
【发布时间】:2020-02-06 14:14:33
【问题描述】:

所以我尝试的是加快使用 Mailchimp 发送邮件的过程。 我想通过简单地更改我的邮件模板中的数据来做到这一点。 我的公司通常是手工完成的,但这需要很多时间。 所以首先我尝试使用 PHP 简单地更改我的邮件模板。 问题是,Mailchimp 只能读取 HTML 文档而完全忽略了 PHP。 我尝试 .htaccess 在我的 HTML 文件中使用 PHP,但 Mailchimp 也不会读取 .htaccess 文件。

问题:我只能加载 HTML 文件,而 Mailchimp 只能读取 HTML 代码。

我的问题:我可以使用 PHP 生成 HTML 文档吗?

让我试着更好地解释我的情况。 可以说这是我的模板, mailing-template.html

<html>
    <head>
        <title>Mailing-Template</title>
    </head>
        <body>
            <div id="productBox">
                <h1 id="productName">Product Name</h1>
                <p id="productInfo">product info</p>
            </div>
        </body>         
</html>

所以对于我的邮件,我需要我的产品名称和产品信息来更改每个产品。 正如我所提到的,因为我想将我的模板导入 Mailchimp,所以除了 html 之外我不能使用其他任何东西。

我需要做的是更改我的 mailing-template.html 中的一些产品信息,而不需要任何其他语言来支持它。 我唯一能想到的就是使用另一种编码语言生成我的邮件模板,而不是使用生成的文件作为我的模板。

我什至不确定这是否可能,或者我是否缺少更好的方法。我对这一切都很陌生,所以这就是我寻求帮助的原因。

珍惜你的时间。 :)

【问题讨论】:

  • 是的,您可以从 PHP 创建 HTML 文件。在变量中生成标记,然后使用file_put_contents 制作您的文件。

标签: php html mailchimp


【解决方案1】:

是的,您可以使用 php 生成 html 文档。

<?php
  //Simply store all the html code in a variable as shown below,
  $pagehtml = "your html will go here";
?>

您可以使用会话将此变量传递到下一页,或者您可以简单地创建一个带有 .php 扩展名的页面并将变量(例如 $pagehtml)内容回显到您想要的位置。

【讨论】:

    【解决方案2】:

    是的,PHP 可以做到这一点,快速示例

    //create html file for writing
    $file = fopen("file.html", "a+") or  die ( "File creation failed".error_get_last() );
    
    //add your content to $content variable
    $content='<html>
        <head>
            <title>Mailing-Template</title>
        </head>
            <body>
                <div id="productBox">
                    <h1 id="productName">Product Name</h1>
                    <p id="productInfo">product info</p>
                </div>
            </body>         
    </html>';
    
    //write the content to the file
    fwrite($file, $content);
    
    //close the completed file
    fclose($file);
    

    【讨论】:

    • 动态 OP 可以更改产品名称和产品信息的部分在哪里?
    • 问题是“我可以使用 PHP 生成 HTML 文档吗?”。
    • 不,问题是:“我想通过简单地更改我的邮件模板中的数据来做到这一点。我的公司通常是手动完成的,但它需要很多时间”我>
    • @DjHexy 我的错,应该让我的问题更清楚。你确实回答了我问的问题。
    • @LelioFaieta 是对的,我的实际问题是:“我想通过简单地更改我的邮件模板中的数据来做到这一点。我的公司通常是手动完成的,但它需要很多时间"。
    【解决方案3】:

    感谢大家的帮助! 我知道生成一个 HTML 文件,我可以通过在内容中添加一个变量来更改我的数据。

    //create html file for writing
            $file = fopen("file.html", "a+") or  die ( "File creation failed".error_get_last() );
    
    //set product name
    $productName = "Product Name";
    
            //add content to $content variable
            $content='
            <html>
                <head>
                    <title>Mailing-Template</title>
                </head>
                    <body>
                        <div id="productBox">
                            <h1 id="productName">' . $productName . '</h1>
                            <p id="productInfo">product info</p>
                        </div>
                    </body>         
            </html>';
    
            //write the content to the file
            fwrite($file, $content);
    
            //close the completed file
            fclose($file);
    

    感谢帮助:)

    【讨论】:

      猜你喜欢
      • 2015-02-22
      • 2012-03-27
      • 1970-01-01
      • 2023-03-25
      • 2011-06-22
      • 1970-01-01
      • 2020-10-22
      • 1970-01-01
      • 2010-09-27
      相关资源
      最近更新 更多