我在开发网站上正常工作的以下代码。
add_action('admin_menu', 'Send_registration_email');
function Send_registration_email()
{
add_menu_page('Send registration email Plugin Page', 'Send email registration', 'manage_options', 'Sendemail-plugin', 'sendemail_init');
}
function get_custom_email_html( $heading = false, $mailer , $customer) {
$template = 'emails/my-custom-email-i-want-to-send.php';
return wc_get_template_html( $template, array(
'customer' => $customer,
'email_heading' => $heading,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $mailer
) );
}
function sendemail_init()
{
if(isset($_POST['sendemail'])) {
// load the mailer class
$mailer = WC()->mailer();
//format the email
$recipient = $_POST['email'];
$subject = __("Via deze link kunt u zich registreren!", 'theme_name');
$content = get_custom_email_html( $subject, $mailer,$_POST['gdiscounts'] );
$headers = "Content-Type: text/html\r\n";
//send the email through wordpress
$test = $mailer->send( $recipient, $subject, $content, $headers );
var_dump($test);
var_dump($mailer->send( $recipient, $subject, $content, $headers ));
var_dump($mailer->debugEmail());
}
// var_dump((array)Woocommerce_Simple_User_Level_Discount_Field::get_discounts());
$discount = (array)Woocommerce_Simple_User_Level_Discount_Field::get_discounts();
include plugin_dir_path(__FILE__) . '/templates/sendemail_edit.php';
}
这在开发网站上可以很好地工作,但在生产网站上则不能。
原因是我们使用wp_mail_bank插件在生产网站上发送smtp邮件。
邮件未发送,我看不到调试输出,因为我没有付费的插件版本。
所以我的问题是: 为什么WC()-> mailer()无法与邮件银行smtp插件一起使用。 所有其他woocommerce邮件都已成功发送。