SMTP connect()失败...而我正在尝试从我的php文件发送邮件

时间:2013-10-01 08:53:38

标签: php email smtp

我一直试图从我的php文件发送邮件,我收到了这样的错误

**"SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP connect() failed."**

我正处于项目的最后期限,如果有人知道我在这里所做的解决方案或错误,请分享和帮助。 我在这里分享我的代码.........

<?php
    require("C:/xampp/htdocs/conference/PHPMailer-master/class.phpmailer.php");
    require("C:/xampp/htdocs/conference/PHPMailer-master/class.smtp.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
    $mail->Host       = "smtp.gmail.com"; // SMTP server
    $mail->Port       = 465; // SMTP Port
    $mail->Username   = "my email address"; // SMTP account username
    $mail->Password   = "my password";        // SMTP account password

    $mail->SetFrom('my email address', 'xxxx'); // FROM
    $mail->AddReplyTo('my email address', 'xxxx'); // Reply TO

    $mail->AddAddress('someone email address', 'yyyy'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
?>

2 个答案:

答案 0 :(得分:3)

我找到了解决这个问题的方法,

检查您的PHP是否使用 openSSL 扩展程序......!

  1. 从已安装的php文件夹
  2. 编辑 php.ini
  3. 搜索 extension = php_openssl.dll
  4. 首字母将如下所示; extension = php_openssl.dll
  5. 删除';'它看起来像 extension = php_openssl.dll
  6. 如果找不到 extension = php_openssl.dll ,请添加此行 extension = php_openssl.dll
  7. 然后重新启动您的Xampp或LAMP或APACHE服务器(取决于您使用的是哪一个)。
  8. 希望这种方法可以解决你的问题...

答案 1 :(得分:-3)

中有双引号
$mail->Host       = "smtp.gmail.com"; // SMTP server

请删除双引号。

$mail->Host       = 'smtp.gmail.com'; // SMTP server