如何在 Cpanel 上启用建立 SMTP 连接?
How to I enable establish SMTP connection on Cpanel?
我希望能够通过 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
有时您的 CPanel 帐户默认禁用外部 SMTP 访问,您必须联系您的服务提供商为您重新启用它。
我希望能够通过 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
有时您的 CPanel 帐户默认禁用外部 SMTP 访问,您必须联系您的服务提供商为您重新启用它。