MP_SheduleEmails::schedule_first_send_email()
Send first email by schedule.
Source Source
File: mortgage-platform/Inc/MP_SheduleEmails.php
public function schedule_first_send_email() {
$leads = new \WP_Query(
array(
'post_type' => MortgagePlatform::$lead,
'posts_per_page' => -1,
'post_status' => array( 'publish', 'pending' ),
'meta_key' => MortgagePlatform::$prefix . 'first_send',
'meta_value' => array( time(), time() - HOUR_IN_SECONDS + HOUR_IN_SECONDS ),
'meta_compare' => 'BETWEEN',
)
);
if ( $leads->have_posts() ) {
while ( $leads->have_posts() ) {
$leads->the_post();
$eol = PHP_EOL;
$mail_from = get_option( MortgagePlatform::$prefix . 'email' )['email'] ? get_option( MortgagePlatform::$prefix . 'email' )['email'] : get_option( 'admin_email' );
$post_id = $leads->post->ID;
$mail_to = get_post_meta( $post_id, MortgagePlatform::$prefix . 'lead_email', true );
$mail_subject = get_option( MortgagePlatform::$prefix . 'email' )['first_email_subject'] ? get_option( MortgagePlatform::$prefix . 'email' )['first_email_subject'] : '';
$mail_text = get_option( MortgagePlatform::$prefix . 'email' )['first_email_text'] ? get_option( MortgagePlatform::$prefix . 'email' )['first_email_text'] : '';
$headers = 'MIME-Version: 1.0' . $eol;
$headers .= 'Content-type:text/html;charset=UTF-8' . $eol;
$headers .= 'From: ' . $mail_from . $eol;
$mailsend = $this->send_email( $mail_to, $mail_subject, $mail_text, $headers );
if ( $mailsend ) {
delete_post_meta( $post_id, MortgagePlatform::$prefix . 'first_send' );
$mailsend = $mailsend ? 'Success' : 'Error';
//$lead_log['lead_first_email_by_schedule'] = current_time( "Y-m-d H:i:s" ) . ' : ' . $mailsend;
//add_metadata( 'post', $post_id, MortgagePlatform::$prefix . 'lead_log', wp_slash( $lead_log ), '' );
MP_Logs::set_logs( $post_id, 'lead_first_email_by_schedule', $mailsend );
}
}
}
wp_reset_postdata();
}
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |