如何在Cpanel上建立SMTP连接?

时间:2019-09-25 10:49:32

标签: smtp cpanel slim swiftmailer

我希望能够通过SMTP从应用程序发送电子邮件,并且我不想将sendmail用作传输工具。

$transport = (new \Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
            ->setUsername('afashaisakiye@gmail.com')
            ->setSourceIp('0.0.0.0')
            ->setPassword('**********');
        //$transport = (new \Swift_SendmailTransport('/usr/sbin/sendmail -bs'));




        // Create the Mailer using your created Transport
        $mailer = new \Swift_Mailer($transport);
        // Create a message
        $message = (new \Swift_Message('This is the message subject'))
            ->setFrom(['afashaisakiye@gmail.com' => 'Smartup Digital team'])
            ->setTo([afasha@linearc.top => 'Isakiye Afasha'])
            ->setBody("thisis an html body", 'text/html', 'iso-8859-2');
        // Send the message
        $result = $mailer->send($message);

这在我的计算机上有效,但是当我在Cpannel上部署时,出现此错误。

Type: Swift_TransportException
Message: Connection could not be established with host smtp.gmail.com [Connection refused #111]
File: /home/linearct/checkin/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php
Line: 269

1 个答案:

答案 0 :(得分:0)

默认情况下,您的CPanel帐户有时会禁用外部SMTP访问,您必须联系服务提供商才能重新启用它。