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_1@example.com',
'subject' => $subject_email,
'message' => $customer_email
),
array(
'to' => 'email_2@example.com',
'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.
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
– Tom J Nowell♦ Jun 15 '20 at 11:07$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. – Dhimas Kirana Jun 15 '20 at 23:33