Mailgun : Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open

Mailgun : Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open

我使用了以下代码,并将这些文件放在与我正在 运行 发送邮件的脚本相同的目录中。即使我尝试提供在线 link.

,异常仍继续抛出

我正在我的本地主机上尝试这段 PHP 代码,您可以从下面的错误中找出来

# Include the Autoloader (see "Libraries" for install instructions)
require 'mail/vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = new Mailgun('key-secret');
$domain = "mydomain";

    $result = $mgClient->sendMessage($domain, array(
    'from'    => 'email',
             'to'      => 'email',
             'bcc'     => 'email',
             'subject' => "Sending Attachment 2",
             'text'    => "Sending Attachment",
             'html'    => "Sending Attachment",
             'attachment-1'=> 'test.xml'
),  array("attachment" => array(
                                    array('filePath'   => '@/file.txt', 
                                          'remoteName' => 'file.txt'),
                                    array('filePath'   => '@/test.txt', 
                                          'remoteName' => 'test.txt'))));

Fatal error: Uncaught exception 'Guzzle\Common\Exception\InvalidArgumentException' with message 'Unable to open /file.txt for reading' in C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php:53 Stack trace: #0 C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php(28): Guzzle\Http\Message\PostFile->setFilename('@/file.txt') #1 C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\EntityEnclosingRequest.php(199): Guzzle\Http\Message\PostFile->__construct('attachment', '@/file.txt', NULL, 'file.txt') #2 C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\src\Mailgun\Connection\RestClient.php(52): Guzzle\Http\Message\EntityEnclosingRequest->addPostFile('attachment', '@/file.txt', NULL, 'file.txt') #3 C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\src\Mailgun\Mailgun.php(80): Mailgun\Connection\RestClient->post('hotelpalmshore....', Array, Array) #4 C:\xampp\htdocs\zendeskapis\mail\vendor\mailgun\mailgun-php\ in C:\xampp\htdocs\zendeskapis\mail\vendor\guzzle\guzzle\src\Guzzle\Http\Message\PostFile.php on line 53

如异常所述,您的文件路径似乎不正确。

假设您使用的是 nix 系统,您的 file.txt 应该就在 / 下面,这似乎不太可能我.

如果您在 windows 系统上,路径 /file.txt 没有任何意义。

首先尝试硬编码您的路径,一旦可行就动态设置它