我有这段代码:
<?php
$gregorianMonth = date('n');
$gregorianDay = date('j');
$gregorianYear = date('Y');
$jdDate = gregoriantojd($gregorianMonth,$gregorianDay,$gregorianYear);
$hebrewMonthName = jdmonthname($jdDate,4);
$hebrewDate = jdtojewish($jdDate);
list($hebrewMonth, $hebrewDay, $hebrewYear) = split('/',$hebrewDate);
echo "<p style='color:#000000; font-size:11px'>Today's Hebrew Date: $hebrewDay $hebrewMonthName $hebrewYear</p>";
$table_name = "candle_number";
global $wpdb;
$results = $wpdb->get_results("SELECT email FROM `{$table_name}` WHERE date_pref = \"hebrew\" AND datehebrew LIKE \"$hebrewDay $hebrewMonthName 5%\"");
$final_output = array();
foreach( $results as $rs ){
$final_output[] = $rs->email;
}
echo json_encode($final_output);
echo count($final_output, COUNT_RECURSIVE);
$automation_id = 'ed6e9exxxx';
$api_key = '206b84dd296928a4b134b18xxxxxxxxx-us10';
$email = $_POST[ implode(",",$final_output)];
hebrew_date_mail($automation_id, $api_key, $email);
?>
由于它是Wordpress,我将其添加到functions.php
文件中:
<?php
function hebrew_date_mail($automation_id, $api_key, $email){
$data = array(
'apikey' => $api_key,
'email_address' => $email,
);
$mch_api = curl_init();
curl_setopt($mch_api, CURLOPT_URL, 'https://usX.api.mailchimp.com/3.0/automations/' . $automation_id . '/emails/491fec26f1/queue');
curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true);
curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($mch_api, CURLOPT_TIMEOUT, 10);
curl_setopt($mch_api, CURLOPT_POST, true);
curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($data) );
}
它的作用基本上是检查希伯来语的日期和月份,如果数据库中的任何用户匹配,它会发送到我的MC API自动化。但它不起作用,我认为它与结果数组有关。
问题在于我还不太了解cURL
或JSON
,而且我并不完全知道为什么这不起作用。谢谢。