我已成功为交易电子邮件设置了Mailgun帐户。
问题;
我希望我的电子邮件内容在我的电子邮件模板中是动态的,请帮助甚至我的文件附件无效
<?php
$filePath='@/home/allinclende/public_html/apply/CIW.pdf';
$message = $message;
$html = file_get_contents('email_1.html');
$html .= $message;
$mgClient = new Mailgun('key-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
//enter domain which you find in Default Password
$domain = "apply.allinc.com";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'Jane Doe <jdoe@allinc.com>',
'to' => $add,
'cc' => 'inquiry <info@allinc.com>',
'subject' => $subject,
'text' => $message,
'html' => $html,
'attachment[1]' => $filePath
));
?>
答案 0 :(得分:0)
在您的email_1.html文件中包含一些独特的占位符。创建一个包含它们的数组:
$search = array("FIRSTNAME", "LASTNAME", "APPOINTMENTDATE");
查询您的数据库并获取变量以替换每个变量,并创建一个数组:
$replace = array($firstname, $lastname, $appointmentdate);
然后它就像:
一样简单$customhtml = str_replace($search, $replace, $html);
通过mailgun发送$customhtml
,然后再次循环以个性化每位客户的电子邮件
发送附件的正确构造如下:
$result = $mgClient->sendMessage($domain, array(
'from' => 'Jane Doe <jdoe@allinc.com>',
'to' => $add,
'cc' => 'inquiry <info@allinc.com>',
'subject' => $subject,
'text' => $message,
'html' => $html
), array(
'attachment' => array('@/home/allinclende/public_html/apply/CIW.pdf')
));