/** * Send OptIn email * * @param string $email Email of subscribed user * @param string $first_name First Name of subscribed user * @param string $last_name Last Name of subscribed user * @return bool */ public static function send_confirmation_email($email, $first_name = '', $last_name = '', $from_settings = false) { $subject = Sendgrid_Tools::get_mc_signup_email_subject(); $content = Sendgrid_Tools::get_mc_signup_email_content(); $content_text = Sendgrid_Tools::get_mc_signup_email_content_text(); if (false == $subject or false == $content or false == $content_text) { return false; } $subject = stripslashes($subject); $content = stripslashes($content); $content_text = stripslashes($content_text); $to = array($email); $token = Sendgrid_OptIn_API_Endpoint::generate_email_token($email, $first_name, $last_name); $transient = get_transient($token); if ($transient and isset($transient['email']) and !$from_settings) { return false; } if (false == set_transient($token, array('email' => $email, 'first_name' => $first_name, 'last_name' => $last_name), 24 * 60 * 60) and !$from_settings and $transient) { return false; } $confirmation_link = site_url() . '?__sg_api=1&token=' . $token; $headers = new SendGrid\Email(); $headers->addSubstitution('%confirmation_link%', array($confirmation_link))->addCategory('wp_sendgrid_subscription_widget'); add_filter('sendgrid_mail_text', function () use(&$content_text) { return $content_text; }); $result = wp_mail($to, $subject, $content, $headers); return $result; }