我已经下载了class.phpmailer.php,class.smtp.php和PHPMailerAutoload.php。
错误:
2014-06-21 15:24:30 SMTP ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (4296) SMTP connect() failed. Mailer Error: SMTP connect() failed.
使用给定的$ email,$ subject和$ body执行smtp电子邮件的PHP代码。
<?php
require_once("..\htmlphp\class.phpmailer.php");
date_default_timezone_set('America/Eastern');
include("..\htmlphp\class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->Username = "self@live.com";
$mail->Password = "pass1";
$mail->From="self@live.com";
$mail->Subject = $subject;
$mail->Body=$body;
$mail->AddAddress($email);
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>