/** * Sends a test email using the parameters specified in the settings page * * @param mixed $params array of parameters from $_POST * * @return mixed response array with message and status */ private static function send_test_email($params) { $to = $params['sendgrid_to']; if (!Sendgrid_Tools::is_valid_email($to)) { return array('message' => 'Email address in field "To" is not valid.', 'status' => 'error', 'error_type' => 'sending'); } $subject = stripslashes($params['sendgrid_subj']); $body = stripslashes($params['sendgrid_body']); $headers = $params['sendgrid_headers']; if (!Sendgrid_Tools::valid_emails_in_headers($headers)) { return array('message' => 'One or more email addresses in field "headers" are not valid.', 'status' => 'error', 'error_type' => 'sending'); } if (preg_match('/content-type:\\s*text\\/html/i', $headers)) { $body_br = nl2br($body); } else { $body_br = $body; } $sent = wp_mail($to, $subject, $body_br, $headers); if (true === $sent) { return array('message' => 'Email was sent.', 'status' => 'updated'); } return array('message' => 'Email wasn\'t sent.', 'status' => 'error', 'error_type' => 'sending'); }