这个问题在这里已有答案:

我从2016年开始看到phpmailer的问题 . 我花了4天但它还没有用 . 我尝试了很多样品 . 所以请分享发送电子邮件代码 . 任何代码给我的任何方法 . 我很害怕

每次我改变一些东西都有不同的错误 . 但通常我看到这个错误:

**** 2018-11-19 12:10:33 SMTP错误:无法连接到服务器:无法 Build 连接,因为目标计算机主动拒绝它 . (10061)SMTP connect()失败 . https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting致命错误:未捕获的PHPMailer \ PHPMailer \例外:SMTP connect()失败 . https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting in C:\ xampp \ htdocs \ email \ PHPMailer-master \ src \ PHPMailer.php:1775 Stack trace:#0 C:\ xampp \ htdocs \ email \ PHPMailer-master \ src \ PHPMailer.php(1516):PHPMailer \ PHPMailer \ PHPMailer-> smtpSend('Date:Mon,19 N ...','hello \ r \ n')#1 C:\ xampp \ htdocs \ email \ PHPMailer-master \ src \ PHPMailer.php(1352):PHPMailer \ PHPMailer \ PHPMailer-> postSend()#2 C:\ xampp \ htdocs \ email \ mail3.php(33):PHPMailer \ PHPMailer \ PHPMailer- >发送()#3 在1775行的C:\ xampp \ htdocs \ email \ PHPMailer-master \ src \ PHPMailer.php中抛出****

my code is

<?phpenter code here
date_default_timezone_set('Etc/UTC');
use PHPMailer\PHPMailer\PHPMailer;
require("PHPMailer-master/src/PHPMailer.php");
require("PHPMailer-master/src/SMTP.php");
require("PHPMailer-master/src/Exception.php");
//require 'vendor/autoload.php';

//fatch data from form
//fatch data from form


$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPSecure = false;
$mail->SMTPAuth = false;
$mail->Host = 'localhost';
$mail->Port = 25; //25 local //465 local //80 godaddy

$mail->Username = 'xxx@xxx.in';
$mail->Password = 'xxxx';
//$mail->Debugoutput = 'html';
$mail->isHTML(true);
$mail->From = 'xxx@xxx.in';
$mail->FromName = 'abcd';
$mail->AddAddress('yyy@yyy.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'ASK FOR A DEMO';
$mail->Body    = 'hello';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
    echo "<script>alert('".$email." thank you!');</script>";
}

?>
<h3>hello</h3>