Last active
November 25, 2024 23:19
-
-
Save vanpariyar/022a7dfc8dbbbc984b5517b22f73386c to your computer and use it in GitHub Desktop.
send email with ACF email templates wordpress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function send_email_to_admin($post_id , $post_type ){ | |
switch ($post_type) { | |
case 'nominee-entries': | |
$terms = wp_get_post_terms( $post_id, 'award-category', array( 'fields' => 'names' ) ); | |
$uploaded_file = get_field('uploaded_file', $post_id); | |
$fields = array( | |
'%{FIRST-NAME}%' => get_field('first_name', $post_id), | |
'%{LAST-NAME}%' => get_field('last_name', $post_id), | |
'%{COMPANY-NAME}%' => get_field('company_name', $post_id), | |
'%{PROJECT-NAME}%' => get_field('project_name', $post_id), | |
'%{PROJECT-DETAILS}%' => get_field('project_details', $post_id), | |
'%{COUNTRY}%' => get_field('country', $post_id), | |
'%{CONTACT}%' => get_field('contact_number', $post_id), | |
'%{EMAIL}%' => get_field('email', $post_id), | |
'%{CATEGORY}%' => $terms[0], | |
'%{FILE-URL}%' => $uploaded_file['url'], | |
); | |
global $mail_constant; | |
$admin_email = get_field('admin_email', 'option'); | |
$email_subject = get_field('email_subject', 'option'); | |
$email_subject = empty($email_subject) ? $mail_constant['award']['email_subject'] : $email_subject; | |
$mail_content = get_field('mail_content', 'option'); | |
$mail_content = empty($mail_content) ? $mail_constant['award']['mail_content'] : $mail_content; | |
foreach ($fields as $key => $value) { | |
$mail_content = str_replace($key, $value, $mail_content); | |
} | |
// return $mail_content; | |
$headers = array('Content-Type: text/html; charset=UTF-8','From:'.$admin_email); | |
wp_mail( $admin_email, $email_subject, $mail_content, $headers); | |
break; | |
case 'sponsor-entries': | |
$fields = array( | |
'%{ORGANISATION-NAME}%' => get_field('organization_name', $post_id), | |
'%{CONTACT-NAME}%' => get_field('contact_name', $post_id), | |
'%{DESIGNATION}%' => get_field('designation', $post_id), | |
'%{CONTACT}%' => get_field('contact_number', $post_id), | |
'%{EMAIL}%' => get_field('email', $post_id), | |
); | |
global $mail_constant; | |
$admin_email = get_field('admin_email', 'option'); | |
$email_subject = get_field('sponsor_email_subject', 'option'); | |
$email_subject = empty($email_subject) ? $mail_constant['sponsor']['email_subject'] : $email_subject; | |
$mail_content = get_field('sponsor_mail_content', 'option'); | |
$mail_content = empty($mail_content) ? $mail_constant['sponsor']['mail_content'] : $mail_content; | |
foreach ($fields as $key => $value) { | |
$mail_content = str_replace($key, $value, $mail_content); | |
} | |
// return $mail_content; | |
$headers = array('Content-Type: text/html; charset=UTF-8','From:'.$admin_email); | |
wp_mail( $admin_email, $email_subject, $mail_content, $headers); | |
die(); | |
break; | |
default: | |
break; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment