【问题标题】:mailgun, guzzle curl errormailgun,guzzle curl错误
【发布时间】:2015-12-28 16:49:02
【问题描述】:

我在尝试使用 mailgun 附加文件时遇到此错误。

Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 26: couldn't open file "zzz.txt" [url] https://api.mailgun.net/v2/sandbox8df78f0cdbc646aeb2a46999a8c6def5.mailgun.org/messages' in C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:359 Stack trace: #0 C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(292): Guzzle\Http\Curl\CurlMulti->isCurlException(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array) #1 C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(257): Guzzle\Http\Curl\CurlMulti->processResponse(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Curl\CurlHandle), Array) #2 C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php(240): Guzzle\Http\Curl\CurlMulti->processMessages() #3 C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\C in C:\xampp\htdocs\tutlage\newsletter\vendor\guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php on line 359

如何解决这个问题? 是证书问题吗?

我附上这样的文件(这里没有错)(文件可以通过php访问):

$mg->sendMessage($domain, array('from'    => '...',
                                'to'      => '...',
                                'subject' => '...', 
                                'text'    => '...'
                                ), array(
                                    'attachment' => array('zzz.txt')
                                )
);

【问题讨论】:

    标签: php guzzle mailgun


    【解决方案1】:

    显然,在当前目录中找不到文件zzz.txt,您应该指定它的绝对位置或相对位置,例如,使用__DIR__ 常量:

    $mg->sendMessage(
        $domain, 
        array(
            'from' => '...',
            'to' => '...',
            'subject' => '...', 
            'text' => '...',
        ), 
        array(
            'attachment' => array(
                __DIR__ . '/foo/bar/zzz.txt',
            ),
        ),
    );
    

    有关参考,请参阅http://php.net/manual/en/language.constants.predefined.php

    【讨论】:

    • 谢谢(windows 的反斜杠)
    【解决方案2】:

    这对我很有用。试试下面的代码

    define('ROOTPATH', dirname(__FILE__));
    $filePath = ROOTPATH.'/textfile.txt';
    $result = $mgClient->sendMessage("$domain",
        array('from'    => 'from address',
            'to'      => 'to addreess',
            'subject' => 'Find Attachment',         
            'html'    => '<h2>HTML</h2>'),
        array('attachment' => array($filePath)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 2016-09-16
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多