来自https://github.com/PHPMailer/PHPMailer的文件
邮件错误:SMTP connect() failed.require_once('./class.phpmailer.php')
$mail = new PHPMailer()
$mail->IsSMTP()
$mail->Host = "smtp.gmail.com"
$mail->Port = "465"
$mail->SMTPAuth = "true"
$mail->SMTPSecure = "ssl"
$mail->Username = "mymail@gmail.com"
$mail->Password = "password"
//build the message
$mail->IsHTML(true)
$mail->From = "mymail@gmail.com"
$mail->AddAddress("mymail@mydomain.com")
$mail->Subject = "An HTML Message"
$mail->Body = "Hello, <b>my friend</b>! 'n'n This message uses HTML entities!"
if($mail->Send()) {
echo 'Message is sent'
}
else {
echo 'Message was not sent..'
echo 'Mailer error: ' . $mail->ErrorInfo
}
必须启用OpenSSL。例如,在php.ini中,删除行中的';':
extension=php_openssl.dll
如果你已经启用了"OpenSSL",创建一个新的php文件,把它放在:
<?php echo phpinfo();?>
查找此信息:
OpenSSL support : enabled
-----ADD完整代码-------------
我已经测试了这段代码,它正在为我运行:
<?php
require_once('./class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP() ;
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true ;
$mail->SMTPSecure = "ssl";
$mail->Username = "mymail@gmail.com";
$mail->Password = "mypassword";
//build the message
$mail->IsHTML(true);
$mail->From = "mymail@gmail.com";
$mail->AddAddress("mymail@gmail.com");
$mail->Subject = "An HTML Message";
$mail->Body = "Hello, <b>my friend</b>! 'n'n This message uses HTML entities!";
if($mail->Send()) {
echo 'Message is sent';
}
else {
echo 'Message was not sent..';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
?>
所有需要的文件:
http://blog.portekoi.com/stack/Mailer.zip