DEBUG:发送:QUIT无法连接到ssl://smtp.gmail.com:465 [SMTP:无法连接套接字:连接被拒绝(代码:-1,响应:)]

时间:2018-01-20 08:40:12

标签: php sockets email ssl pear-mail

我尝试使用我在Godaddy托管上托管的PHP脚本发送电子邮件。我使用Pear Mail()函数发送电子邮件,但现在我收到错误code: -1, response:

错误:

DEBUG: Send: QUIT
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused (code: -1, response: )]

我的PHP脚本:

<?php
require_once "Mail.php";
session_start();
   define('DB_SERVER', 'localhost');
    define('DB_USERNAME', 'userName');
    define('DB_PASSWORD', 'Password');
    define('DB_NAME', 'DB_Name');

    /* Attempt to connect to MySQL database */
    $link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

    // Check connection
    if($link === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }else{

    $sponcer_id = rand(111111,999999);
    if(isset($_POST['fullname']) && isset($_POST['mobile_no']) && isset($_POST['confirm_password'])){
            $sql = "INSERT INTO register_form (Sponcer_id,refer_id, full_name,mobile,email,password,state,country)
                    VALUES ('".$sponcer_id."', '".$_SESSION["refer"]."', '".$_POST['fullname']."','".$_POST['mobile_no']."','".$_POST['email_id']."','".$_POST['confirm_password']."','".$_POST['state']."','".$_POST['country']."')";
            if ($link->query($sql) === TRUE) {
                $from = 'test@gmail.com';
        $to = $_POST['email_id'];
        $subject = 'Registration Email';
        $body = "Welcome... Your UID =><strong>".$sponcer_id."</strong>";

        $headers = array(
            'From' => $from,
            'To' => $to,
            'Subject' => $subject
        );

        $smtp = Mail::factory('smtp', array(
            'SMTPAuth' => true,
            'host' => 'ssl://smtp.gmail.com',
            'port' => '465',
            'auth' => true,
            'encryption' => STARTTLS,
            'debug' => true,
            'username' => 'test@gmail.com',
            'password' => 'password'
        ));

        //$params['debug'] = 'true'; // Create the mail object using the Mail::factory method
                //$mail_object =& Mail::factory('smtp', $params); // Print the parameters you are using to the page

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail))
        {
            echo('<p>' . $mail->getMessage() . '</p>');
        } else {
            echo('<p>Message successfully sent!</p>');
        }
                // echo "Welcome .... your UID =><strong>".$sponcer_id."</strong> <a href='mainregister.php' class='btn btn-info'><< back</a>";

                //header('Location: register.php');
            } else {
                $_SESSION['message'] = "Error: " . $sql . "<br>" . $conn->error;         
            }
    } 
    }
?>

我已经推荐过这个链接: Send email using the GMail SMTP server from a PHP page

欢迎任何形式的帮助。提前谢谢。

0 个答案:

没有答案