嘗試從我的 Laravel 5.1 應用程式中發送電子郵件時出現此錯誤。此功能在很長一段時間內運行良好,但我停止使用我的應用程式大約一年,現在當我嘗試使用它時出現此錯誤。我認為我沒有對與電子郵件相關的任何內容進行任何更改,因此我不確定原因可能是什么。
這是我的 composer.json 的樣子:
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"barryvdh/laravel-ide-helper": "^2.1",
"laravelcollective/html": "5.1.*",
"nesbot/carbon": "1.39.*",
"intervention/image": "^2.3",
"fzaninotto/faker": "^1.7",
"bugsnag/bugsnag-laravel": "^2.0",
"silber/bouncer": " v1.0.0-rc.4",
"doctrine/dbal": "v2.9",
"spatie/laravel-medialibrary": "^4.0.0",
"rap2hpoutre/laravel-log-viewer": "^2.2"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
編輯:
MailgunTransport.php 檔案如下所示:
<?php
namespace Illuminate\Mail\Transport;
use Swift_Mime_Message;
use GuzzleHttp\Post\PostFile;
use GuzzleHttp\ClientInterface;
class MailgunTransport extends Transport
{
/**
* Guzzle client instance.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $client;
/**
* The Mailgun API key.
*
* @var string
*/
protected $key;
/**
* The Mailgun domain.
*
* @var string
*/
protected $domain;
/**
* THe Mailgun API end-point.
*
* @var string
*/
protected $url;
/**
* Create a new Mailgun transport instance.
*
* @param \GuzzleHttp\ClientInterface $client
* @param string $key
* @param string $domain
* @return void
*/
public function __construct(ClientInterface $client, $key, $domain)
{
$this->key = $key;
$this->client = $client;
$this->setDomain($domain);
}
/**
* {@inheritdoc}
*/
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->beforeSendPerformed($message);
$options = ['auth' => ['api', $this->key]];
$to = $this->getTo($message);
$message->setBcc([]);
if (version_compare(ClientInterface::VERSION, '6') === 1) {
$options['multipart'] = [
['name' => 'to', 'contents' => $to],
['name' => 'message', 'contents' => $message->toString(), 'filename' => 'message.mime'],
];
} else {
$options['body'] = [
'to' => $to,
'message' => new PostFile('message', $message->toString()),
];
}
return $this->client->post($this->url, $options);
}
/**
* Get the "to" payload field for the API request.
*
* @param \Swift_Mime_Message $message
* @return array
*/
protected function getTo(Swift_Mime_Message $message)
{
$formatted = [];
$contacts = array_merge(
(array) $message->getTo(), (array) $message->getCc(), (array) $message->getBcc()
);
foreach ($contacts as $address => $display) {
$formatted[] = $display ? $display." <$address>" : $address;
}
return implode(',', $formatted);
}
/**
* Get the API key being used by the transport.
*
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* Set the API key being used by the transport.
*
* @param string $key
* @return string
*/
public function setKey($key)
{
return $this->key = $key;
}
/**
* Get the domain being used by the transport.
*
* @return string
*/
public function getDomain()
{
return $this->domain;
}
/**
* Set the domain being used by the transport.
*
* @param string $domain
* @return void
*/
public function setDomain($domain)
{
$this->url = 'https://api.mailgun.net/v3/'.$domain.'/messages.mime';
return $this->domain = $domain;
}
}
請注意,此檔案是從 Mailgun 源代碼生成的,該檔案中的任何內容都不是我創建的。
第 67 行是這一行:
if (version_compare(ClientInterface::VERSION, '6') === 1)
按照回復中的建議運行后composer update,我收到以下警告:
Package anahkiasen/underscore-php is abandoned, you should avoid using it. No replacement was suggested.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package jakub-onderka/php-console-color is abandoned, you should avoid using it. Use php-parallel-lint/php-console-color instead.
Package jakub-onderka/php-console-highlighter is abandoned, you should avoid using it. Use php-parallel-lint/php-console-highlighter instead.
Package jeremeamia/superclosure is abandoned, you should avoid using it. Use opis/closure instead.
Package mtdowling/cron-expression is abandoned, you should avoid using it. Use dragonmantank/cron-expression instead.
Package patchwork/utf8 is abandoned, you should avoid using it. Use symfony/polyfill-mbstring or symfony/string instead.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No replacement was suggested.
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
我想知道是否是 swiftmailer 導致了這個問題......我不確定如何讓它按照推薦使用 symfony mailer。
uj5u.com熱心網友回復:
因為您之前說沒問題,所以您似乎只需要將依賴項更新到它們的次要更新即可。
- 首先,備份您的
composer.json檔案并運行composer update并查看它是否有幫助。 - 如果沒有幫助,您可能需要安裝 Guzzle。
- 如果仍然沒有幫助,只需替換備份
composer.json并運行composer install以回滾您的依賴項。然后給我看MailgunTransport.php檔案以供進一步調查。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/533698.html - 如果仍然沒有幫助,只需替換備份
