Swift_Transport_MailTransport class 自 5.4.5 版起已弃用,并将在 6.0 中删除。请改用 Sendmail 或 SMTP 传输
The Swift_Transport_MailTransport class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead
我正在使用 SwiftMailer class 通过 php mail() 函数或 SMTP 发送邮件,具体取决于我的应用程序的配置(开发或生产)。我的代码如下所示:
// Default mailer: php mail() function
$this->transport = \Swift_MailTransport::newInstance();
// If a SMTP host is defined
if (isset($_SITE['site_smtp_host'])) {
$this->transport = \Swift_SmtpTransport::newInstance($_SITE["site_smtp_host"], 587)
->setUsername($_SITE["site_smtp_user"])
->setPassword($_SITE["site_smtp_pass"]);
}
从 SwiftMailer 5.4.5 开始,我收到了这个弃用通知:
Exception: UNKNOWN ERROR (16384): The Swift_Transport_MailTransport
class is deprecated since version 5.4.5 and will be removed in 6.0.
Use the Sendmail or SMTP transport instead.
我应该像使用 Swift_MailTransport
那样使用 Swift_SendmailTransport
吗?它会在相同的环境中工作吗?它是否也使用 php mail() 函数?如果不是,是否不能再将 php mail() 函数与 SwiftMailer 一起使用?
首先,关于 swift 邮件站点的弃用:
It is advised that users do not use this transport if at all possible
since a number of plugin features cannot be used in conjunction with
this transport due to the internal interface in PHP itself.
The level of error reporting with this transport is incredibly weak,
again due to limitations of PHP's internal mail() function. You'll get
an all-or-nothing result from sending.
如果您需要 100% 兼容的解决方案,您需要检查 php.ini
设置和 OS 平台 http://php.net/manual/en/mail.configuration.php
对于 unix 平台,使用 ini_get("sendmail_path")
值调用 ->setCommand
就足够了。对于 windows 平台支持,需要检查 smtp
选项。
事情是这样的。请注意,Sendmail 路径在所有服务器上都不相同。
// Get the Sendmail path
$sendmailPath = ini_get('sendmail_path');
$sendmailPath = ($sendmailPath === false || $sendmailPath === '') ? '/usr/sbin/sendmail -bs' : sendmailPath;
// Create the transport method
$transport = new \Swift_SendmailTransport($sendmailPath);
$mailer = \Swift_Mailer::newInstance($transport); // 5.6 or...
$mailer = new \Swift_Mailer($transport); // ...6.2
// Now compose and send your email
我正在使用 SwiftMailer class 通过 php mail() 函数或 SMTP 发送邮件,具体取决于我的应用程序的配置(开发或生产)。我的代码如下所示:
// Default mailer: php mail() function
$this->transport = \Swift_MailTransport::newInstance();
// If a SMTP host is defined
if (isset($_SITE['site_smtp_host'])) {
$this->transport = \Swift_SmtpTransport::newInstance($_SITE["site_smtp_host"], 587)
->setUsername($_SITE["site_smtp_user"])
->setPassword($_SITE["site_smtp_pass"]);
}
从 SwiftMailer 5.4.5 开始,我收到了这个弃用通知:
Exception: UNKNOWN ERROR (16384): The Swift_Transport_MailTransport class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.
我应该像使用 Swift_MailTransport
那样使用 Swift_SendmailTransport
吗?它会在相同的环境中工作吗?它是否也使用 php mail() 函数?如果不是,是否不能再将 php mail() 函数与 SwiftMailer 一起使用?
首先,关于 swift 邮件站点的弃用:
It is advised that users do not use this transport if at all possible since a number of plugin features cannot be used in conjunction with this transport due to the internal interface in PHP itself.
The level of error reporting with this transport is incredibly weak, again due to limitations of PHP's internal mail() function. You'll get an all-or-nothing result from sending.
如果您需要 100% 兼容的解决方案,您需要检查 php.ini
设置和 OS 平台 http://php.net/manual/en/mail.configuration.php
对于 unix 平台,使用 ini_get("sendmail_path")
值调用 ->setCommand
就足够了。对于 windows 平台支持,需要检查 smtp
选项。
事情是这样的。请注意,Sendmail 路径在所有服务器上都不相同。
// Get the Sendmail path
$sendmailPath = ini_get('sendmail_path');
$sendmailPath = ($sendmailPath === false || $sendmailPath === '') ? '/usr/sbin/sendmail -bs' : sendmailPath;
// Create the transport method
$transport = new \Swift_SendmailTransport($sendmailPath);
$mailer = \Swift_Mailer::newInstance($transport); // 5.6 or...
$mailer = new \Swift_Mailer($transport); // ...6.2
// Now compose and send your email