Эта функция возвращает через Ajax:
).success(resp=> console.log('success '+JSON.parse(resp)));
//Uncaught SyntaxError: Unexpected token A in JSON at position 0
или
).success(resp=> console.log('success '+resp));
//success Array
Пробовал для теста эти настройки для отправки писем через другой плагин - все работает.
Как победить?
/* Create NEW Mail*/
add_action( 'wp_ajax_mail_nps', 'mail_nps' );
function mail_nps(){
$nonce = $_POST['nonce'];
if (wp_verify_nonce($nonce, 'myajax-nonce')) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
try {
global $current_user;
get_currentuserinfo();
$from=$current_user->user_email;
$to=$_POST['to'];
$subject=$_POST['subject'];
$message=$_POST['message'];
//$attachments = array(WP_CONTENT_DIR . $_POST['file']);
$headers = 'From: Aboriginal <'.$from.'>' . "\r\n";
$phpmailer = new PHPMailer;
$phpmailer->isSMTP();
$phpmailer->Host = 'email-smtp.us-east-1.amazonaws.com';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 25;
$phpmailer->Username = 'AKIAJ2x';
$phpmailer->Password = "93nUqA1xxx";
//Set the Email
$phpmailer->AddAddress('info@xxx', 'Test');
$phpmailer->SetFrom($from, 'XXX');
$phpmailer->Subject = $headers;
$phpmailer->MsgHTML($message);
//$phpmailer->AddAttachment($attachments);
$success=$phpmailer->send();
//send the message, check for errors
if ($success) {
printf(['mailError' => false, 'message' => 'email sent! ' . $phpmailer->ErrorInfo] );
} else {
printf(['mailError' => true, 'message' => 'email error! ' . $phpmailer->ErrorInfo]);
}
} catch (phpmailerException $e) {
printf(['mailError' => false, 'message' => 'email error! ' . $e->errorMessage()] ); //Pretty error messages from PHPMailer
} catch (Exception $e) {
printf(['mailError' => false, 'message' => 'email error! ' . $e->getMessage()]); //Boring error messages from anything else!
}
}
exit();
}