需要修复PHP邮件程序错误

需要修复PHP邮件程序错误,php,email,phpmailer,Php,Email,Phpmailer,我正在使用PHP mailer实现邮件功能。 代码不是在联机上工作,而是在本地计算机上工作。本地机器代码成功发送邮件,但在线网站显示以下错误: SMTP -> ERROR: Failed to connect to server: () SMTP Error: Could not connect to SMTP host. 代码是: <?php include "classes/class.phpmailer.php"; // include the class name

我正在使用PHP mailer实现邮件功能。 代码不是在联机上工作,而是在本地计算机上工作。本地机器代码成功发送邮件,但在线网站显示以下错误:

SMTP -> ERROR: Failed to connect to server: ()
SMTP Error: Could not connect to SMTP host. 
代码是:

<?php
    include "classes/class.phpmailer.php"; // include the class name

    $mail1 = new PHPMailer(); // create a new object
    $mail1->IsSMTP(); // enable SMTP
    $mail1->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail1->SMTPAuth = true; // authentication enabled
    $mail1->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail1->Host = "smtp.gmail.com";
    $mail1->Port = 465; // or 587
    $mail1->IsHTML(true);
    $mail1->Username = "yourmail@gmail.com";
    $mail1->Password="password";        
    $mail1->SetFrom("yourmail@gmail.com");
    $mail1->Subject = "Working";
    $mail1->Body ="Hi, you got email";
    $mail1->AddAddress("yourmail2@gmail.com"); 
    $mail1->Send(); 
?>

首先,您必须编辑“php.ini”以找到此文件,并使用WAMP服务器中的以下代码显示phpinfo。创建一个php文件并添加此内容

<?php
     echo phpinfo();
?>

你试过587端口吗?没有,那是什么?您的意思是端口465不工作吗?请尝试$mail1->port=587
//add these codes if not written
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;

//You have to change these parameters to your requirements.


$mail->Username = “abc@gmail.com”; // GMAIL username
$mail->Password = “abcdefgh”; // GMAIL password
//..code ... There are many other functions to attach file etc.. For that refer doc file.
$mail->AddAddress(“destination@gmail.com”,”Nick name”);