dousheyan0375 2018-01-20 08:40
浏览 79

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

I'm trying to send an email using PHP script that I'm hosted on Godaddy hosting. I'm using Pear Mail() function to send emails, but now I'm getting an error code: -1, response:

Error:

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

My PHP Script:

<?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;         
            }
    } 
    }
?>

I've referred this link: Send email using the GMail SMTP server from a PHP page

Any kind of help is welcome. Thanks in advance.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度