我已经使用composer下载了Swift-mailer,但是当我去测试它时,我不断收到错误消息。
这就是我设置的内容:
<?php
require_once '/path/to/vendor/autoload.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.justbitestreats.com', >25))
->setUsername('XXXXXX')
->setPassword('XXXXXX');
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
// Create a message
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['[email protected]' => 'Julie'])
->setTo(['[email protected]', '[email protected]' => 'JBT'])
->setBody('Here is the message itself');
// Send the message
$result = $mailer->send($message);
我也试过使用sendmail:
<?php
require_once '/path/to/vendor/autoload.php'(include_path='D:\xampp\php\PEAR');
// Create the Transport
$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('Wonderful Subject'))
->setFrom(['[email protected]' => 'Julie'])
->setTo(['[email protected]' => 'A name'])
->setBody('Here is the message itself');
// Send the message
$result = $mailer->send($message);
我一直收到相同的错误消息
这是错误消息:
警告:require_once(/path/to/vendor/autoload.php):无法打开流:第2行的D:\ xampp \ htdocs \ dashboard \ JBT-Emails \ sendmail.php中没有此类文件或目录
致命错误:require_once():在D:\ xampp \ htdocs \ dashboard \ JBT-Emails \中打开所需的'/path/to/vendor/autoload.php'(include_path ='D:\ xampp \ php \ PEAR')失败sendmail.php在第2行
如果你已经通过PHP中的composer下载了一个包,那么你应该包括像这样的自动加载器 -
require_once realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . './vendor/autoload.php');
我在你的错误中注意到你的路径是 -
d:\ XAMPP \ htdocs中\仪表板\ JBT-电子邮件\ sendmail.php
如果您直接在sendmail.php
中包含供应商文件夹,那么它可能无效,因此您应该尝试提供如上所述的完整路径,它将找到该文件。