Example #1
0
 function swpsmtp_test_mail($to_email, $subject, $message)
 {
     $errors = '';
     $swpsmtp_options = get_option('swpsmtp_options');
     require_once ABSPATH . WPINC . '/class-phpmailer.php';
     $mail = new PHPMailer();
     $charset = get_bloginfo('charset');
     $mail->CharSet = $charset;
     $from_name = $swpsmtp_options['from_name_field'];
     $from_email = $swpsmtp_options['from_email_field'];
     $mail->IsSMTP();
     if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
         $mail->SMTPAuth = true;
         $mail->Username = $swpsmtp_options['smtp_settings']['username'];
         $mail->Password = swpsmtp_get_password();
     }
     if ($swpsmtp_options['smtp_settings']['type_encryption'] !== 'none') {
         $mail->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
     }
     $mail->Host = $swpsmtp_options['smtp_settings']['host'];
     $mail->Port = $swpsmtp_options['smtp_settings']['port'];
     $mail->SetFrom($from_email, $from_name);
     $mail->isHTML(true);
     $mail->Subject = $subject;
     $mail->MsgHTML($message);
     $mail->AddAddress($to_email);
     $mail->SMTPDebug = 0;
     if (!$mail->Send()) {
         $errors = $mail->ErrorInfo;
     }
     $mail->ClearAddresses();
     $mail->ClearAllRecipients();
     if (!empty($errors)) {
         return $errors;
     } else {
         return 'Test mail was sent';
     }
 }
 function swpsmtp_test_mail($to_email, $subject, $message)
 {
     if (!swpsmtp_credentials_configured()) {
         return;
     }
     $errors = '';
     $swpsmtp_options = get_option('swpsmtp_options');
     require_once ABSPATH . WPINC . '/class-phpmailer.php';
     $mail = new PHPMailer();
     $charset = get_bloginfo('charset');
     $mail->CharSet = $charset;
     $from_name = $swpsmtp_options['from_name_field'];
     $from_email = $swpsmtp_options['from_email_field'];
     $mail->IsSMTP();
     /* If using smtp auth, set the username & password */
     if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
         $mail->SMTPAuth = true;
         $mail->Username = $swpsmtp_options['smtp_settings']['username'];
         $mail->Password = swpsmtp_get_password();
     }
     /* Set the SMTPSecure value, if set to none, leave this blank */
     if ($swpsmtp_options['smtp_settings']['type_encryption'] !== 'none') {
         $mail->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
     }
     /* PHPMailer 5.2.10 introduced this option. However, this might cause issues if the server is advertising TLS with an invalid certificate. */
     $mail->SMTPAutoTLS = false;
     /* Set the other options */
     $mail->Host = $swpsmtp_options['smtp_settings']['host'];
     $mail->Port = $swpsmtp_options['smtp_settings']['port'];
     $mail->SetFrom($from_email, $from_name);
     $mail->isHTML(true);
     $mail->Subject = $subject;
     $mail->MsgHTML($message);
     $mail->AddAddress($to_email);
     $mail->SMTPDebug = 0;
     /* Send mail and return result */
     if (!$mail->Send()) {
         $errors = $mail->ErrorInfo;
     }
     $mail->ClearAddresses();
     $mail->ClearAllRecipients();
     if (!empty($errors)) {
         return $errors;
     } else {
         return 'Test mail was sent';
     }
 }
 function swpsmtp_test_mail($to_email, $subject, $message)
 {
     $errors = '';
     $swpsmtp_options = get_option('swpsmtp_options');
     require_once ABSPATH . WPINC . '/class-phpmailer.php';
     $mail = new PHPMailer();
     $from_name = utf8_decode($swpsmtp_options['from_name_field']);
     $from_email = $swpsmtp_options['from_email_field'];
     $mail->IsSMTP();
     /* If using smtp auth, set the username & password */
     if ('yes' == $swpsmtp_options['smtp_settings']['autentication']) {
         $mail->SMTPAuth = true;
         $mail->Username = $swpsmtp_options['smtp_settings']['username'];
         $mail->Password = swpsmtp_get_password();
     }
     /* Set the SMTPSecure value, if set to none, leave this blank */
     if ($swpsmtp_options['smtp_settings']['type_encryption'] !== 'none') {
         $mail->SMTPSecure = $swpsmtp_options['smtp_settings']['type_encryption'];
     }
     /* Set the other options */
     $mail->Host = $swpsmtp_options['smtp_settings']['host'];
     $mail->Port = $swpsmtp_options['smtp_settings']['port'];
     $mail->SetFrom($from_email, $from_name);
     $mail->isHTML(true);
     $mail->Subject = utf8_decode($subject);
     $mail->MsgHTML($message);
     $mail->AddAddress($to_email);
     $mail->SMTPDebug = 0;
     /* Send mail and return result */
     if (!$mail->Send()) {
         $errors = $mail->ErrorInfo;
     }
     $mail->ClearAddresses();
     $mail->ClearAllRecipients();
     if (!empty($errors)) {
         return $errors;
     } else {
         return 'Test mail was sent';
     }
 }