在PHP中生成HTML文档

问题描述 投票:0回答:3

所以我正在尝试加快使用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>

因此,对于我的邮件,我需要我的产品名称和产品信息才能更改每个产品。正如我提到的那样,我无法使用HTML之外的任何东西,因为我想将模板导入Mailchimp。

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

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

感谢您的时间。 :)

php html mailchimp
3个回答
0
投票

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

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

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


0
投票

是的,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);

0
投票

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

//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);

感谢帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.