问题描述
我正在尝试使用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;" />
解决方法
我通过像这样的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,$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,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;
}