首页 > 解决方案 > 如何将网站内容动态导入mautic

问题描述

我正在尝试使用 mautic 向用户发送时事通讯电子邮件,为了将其发送给一部分用户,我在频道 -> 电子邮件的构建器中复制并粘贴了网站的 html 代码。

但是我如何动态实现它,因为我有一些动态内容,例如:

<a href="https://www.website.com/?post_type=post&p=835383" target="_blank">
<img src="https://www.website.com/wp-content/uploads/2020/08/237228_cx__cy__cw__ch_-423x317.jpeg" width="100%" height="auto" style="display: block;" />

标签: mautic

解决方案


我通过 file_get_contents 函数来做到这一点:

$html_string = file_get_contents('http://the url I want to import/');
     $date = date('Y_m_d H:i');
     $name=$_POST["newsletter"] . $date;
     $subject=$_POST["subject"];
     $segment=$_POST["segment"];
     $result = httpPost("https://mautic url/api/emails/new",$html_string,$name,$subject,$segment);

function httpPost($url,$params,$name,$subject,$segment)
{
  $header = array(
    "Authorization: Basic encoded username and password"
  );

    $postData = array( 'name' => $name, 'subject' => $subject, 'customHtml' => $params ,'emailType'=>'list', 'lists'=> [$segment] );
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, true);
    curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POST, count($postData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    $output=curl_exec($ch);
    curl_close($ch);
    return $output;

}

推荐阅读