我真的希望有人能帮助我。我不知道我的问题会是什么原因。但是有一个错误说,
SMTP错误:无法连接到SMTP主机。邮件错误 - > SMTP错误: 无法连接到SMTP主机。
提前感谢您,我感谢您的帮助。
<?php
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "kurokonobasket189@gmail.com";
$mail->Password = "vanishingdrive";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('kurokonobasket189@gmail.com', 'Francis');
$mail->AddAddress('astigvargas189@yahoo.com', 'Arnold');
$mail->Subject = 'using PHPMailer';
$mail->IsHTML(true);
$mail->Body = 'Hi there ,
<br />
this mail was sent using PHPMailer...
<br />
cheers... :)';
if($mail->Send())
{
echo "Message was Successfully Send :)";
}
else
{
echo "Mail Error - >".$mail->ErrorInfo;
}
?>
答案 0 :(得分:0)
从this
下载最新版本并使用此;
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'test@gmail.com'; // your domain username
$mail->Password = 'pass'; // your address password
//$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('test@gmail.com', 'Mailer'); //your domain addres
$mail->addAddress('bilisim_0@outlook.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('test@gmail.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
确保您已打开安全设置; https://myaccount.google.com/lesssecureapps?pli=1
打开设置时也不要打开此部分$mail->SMTPSecure = 'tls';
..