I'm very confused with wp_mail(). Here my code.
function email_notification_for_admin_and_customer( $order_data ) {
$subject_email = 'Subject LOREM IPSUM';
$customer_email = 'Hi Customer, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus, dui eget luctus accumsan, turpis orci malesuada turpis, eget volutpat ante velit a quam.';
$admin_email = 'Hi Admin, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus, dui eget luctus accumsan, turpis orci malesuada turpis, eget volutpat ante velit a quam.';
$send_email = array(
array(
'to' => '[email protected]',
'subject' => $subject_email,
'message' => $customer_email
),
array(
'to' => '[email protected]',
'subject' => $subject_email,
'message' => $admin_email
)
);
foreach ($send_email as $key => $value) {
wp_mail( $value['to'], $value['subject'], $value['message']);
}
}
I want to send email notification to the admin and customer, but wp_mail() only sends first email, which is to customer. Can you help me. Thank you.
I have same problem with this thread, but with different case.
UPDATE THE ANSWER
I'm using the wp_mail filter to format wordpress plain email into my html email template.
add_filter('wp_mail', 'my_wp_mail_filter');
function my_wp_mail_filter($args) {
$message = $args['message'];
$args['message'] = wpet_email_template(apply_filters('wpet_filter_email', $message));
return $args;
}
This is the function to include html template.
function wpet_email_template($message) {
// Render Template
ob_start();
include('custom-email-template.php');
$wpet_template = ob_get_contents();
ob_end_clean();
// Replace Placeholder
$message = str_replace('%%MAILCONTENT%%', $message, $wpet_template);
// Return Template with Data
return $message;
}
The problem is include_once('custom-email-template.php'); then I change to include('custom-email-template.php');
So this is the problem why the email just sent to customer email (first array of $send_email).
Here the answer
wp_mail
returns atrue
andfalse
value to indicate success, but your code doesn't bother to check for this and just assumes that it worked. How are you populating the$send_email
array? I'm assuming you're using actual data in your code, but we can't see that so we can't eliminate it as a possible cause. Is there anything in your PHP error log?@example.com
is a test domain, it won't send emails toexample.com
$send_email
array on this function and there's no error. I see the$send_email
array data as I wish. but the problem is when callingwp_mail
. Iswp_mail
can't call twice? You can check this out stackoverflow.com/questions/52197907/… . I have same problem with this but with different case.