Demande d’information
function my_smtp_wp_test_mail( $to ) { /*if(!swpsmtp_credentials_configured()){ return; }*/ $errors = ''; global $wsOptions; //$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 = $wsOptions["fromname"]; $from_email = $wsOptions["from"];
$subject = __('[My SMTP WP] Your plugin is working','my-smtp-wp'); $message = __('If you are reading this email, it is because your plugin is successfully configured.','my-smtp-wp');
$mail->IsSMTP();
/* If using smtp auth, set the username & password */ if( 'yes' == $wsOptions['smtpauth'] ){ $mail->SMTPAuth = true; $mail->Username = $wsOptions['username']; $mail->Password = $wsOptions['password']; }
/* Set the SMTPSecure value, if set to none, leave this blank */ if ( $wsOptions['smtpsecure'] !== '' ) { $mail->SMTPSecure = $wsOptions['smtpsecure']; }
/* 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 = $wsOptions['host']; $mail->Port = $wsOptions['port']; $mail->SetFrom( $from_email, $from_name ); $mail->isHTML( true ); $mail->Subject = $subject; $mail->MsgHTML( $message ); $mail->AddAddress( $to ); $mail->SMTPDebug = 0;
/* Send mail and return result */ if ( ! $mail->Send() ) $errors = $mail->ErrorInfo;
$mail->ClearAddresses(); $mail->ClearAllRecipients();
if ( ! empty( $errors ) ) { echo '
' . __("Some errors occurred! Check the settings!","my-smtp-wp") . '
'; echo $errors . '
';
} else{ echo '
' . __("Message sent successfully!","my-smtp-wp") . '
'; } }