fsockopen()有关在php中发送邮件的错误

时间:2012-07-18 11:31:48

标签: php ssl smtp xampp fsockopen

我想在用户注册时向用户发送确认电子邮件。我正在使用xampp。当我运行我的php文件时,它返回以下错误:

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\xampp\htdocs\class.smtp.php on line 122

    Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\xampp\htdocs\class.smtp.php on line 122
    Message has not been sent. 

我的php文件中的相关部分:

try
    {
        require("class.phpmailer.php");
        $mail = new PHPMailer();   
        $mail->IsSMTP();
        $mail->Mailer = "smtp";
        $mail->SMTPSecure = "ssl"; 
        $mail->Host = "ssl://smtp.gmail.com";
        $mail->Port = 465;
        $mail->SMTPAuth = true;
        $mail->CharSet="utf-8";
        $mail->Username = "user@gmail.com";
        $mail->Password = "password";
        $mail->From     = "user@gmail.com";
        $mail->FromName="DBE Yazılım";
        $mail->AddAddress($_POST['UserMail']); 
        $mail->Subject  = "Registration Information";
        $mail->Body     = "Hello your password is " . $userpass;
        //$mail->AddAttachment($path);
        $mail->Send();
        if($mail->Send())
            echo 'Message has been sent.';
        else
            echo 'Message has not been sent.';
    }
    catch(Exception $e)
    {
        echo 'hata'.$e->getMessage();
    }

我看过论坛,这个错误通常是关于ssl的。他们说extension=php_openssl.dll必须添加到php.ini中。我添加了这部分,但任何事情都没有改变。这是关于xampp的吗?

提前致谢。

2 个答案:

答案 0 :(得分:2)

正如您在错误消息中看到的那样

  

无法连接到 ssl:// ssl://smtp.gmail.com:465 (无法找到套接字传输“ssl” - 您是否忘记在配置PHP时启用它?)在第122行的C:\ xampp \ htdocs \ class.smtp.php

有一个ssl://太多了

$mail->Host = "smtp.gmail.com"; // instead of ssl://smtp.gmail.com

通常,如果您看到术语“主机”,这实际上意味着“主机”,而不是网址

答案 1 :(得分:-1)

在您的服务器 PHP.ini 文件配置中打开 fsockopen() 函数。你会看到它工作......