如何在Cpanel上建立SMTP连接?

问题描述 投票:0回答:1

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

$transport = (new \Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
            ->setUsername('[email protected]')
            ->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(['[email protected]' => 'Smartup Digital team'])
            ->setTo([[email protected] => '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
smtp cpanel slim swiftmailer
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.