How to use WP phpmailer on separate php file.


/* Send Mail */

require_once '../../../wp-includes/class-phpmailer.php';

//Gmail settings
define('GUSER', 'sender@gmail.com'); // Gmail username
define('GPWD', 'xxxxx'); // Gmail password

//Host settings
define('SMTPUSER', 'xerxis@domain.com'); // sec. smtp username
define('SMTPPWD', '12314'); // sec. password
define('SMTPSERVER', 'mail.domain.com'); // sec. smtp server

function smtpmailer($to, $from, $from_name, $subject, $body, $is_gmail = true) {
global $error;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
if ($is_gmail) {
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
} else {
$mail->Host = SMTPSERVER;
$mail->Username = SMTPUSER;
$mail->Password = SMTPPWD;
}
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}

$msg = 'Hello World';
$subj = 'test mail message';
$to = 'kaixersoft@gmail.com';
$from = 'from@mail.com';
$name = 'test email';

//try using gmail
if (smtpmailer($to, $from, $name, $subj, $msg)) {
echo json_encode(array('status' => 'message send via Gmail'));
//try host settings
} else {
if (!smtpmailer($to, $from, $name, $subj, $msg, false)) {
if (!empty($error)) echo $error;
} else {
echo json_encode(array('status' => 'message send via Host Settings'));
}
}

How to use WP-Includes (3.2.1++)

Load jQuery using Google CDN:

function init_includes() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js');
wp_enqueue_script( 'jquery' );
}
add_action('wp_enqueue_scripts', 'init_includes');

see codex for other built-in includes:
http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_a_default_WordPress_script_from_a_non-default_location