简体   繁体   English

邮枪,枪口卷曲错误

[英]mailgun, guzzle curl error

I have this error when trying to attach a file with mailgun. 尝试使用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

How to fix this ? 如何解决呢? Is it a guzzle certificate issue ? 难得的证书问题吗?

I attach the file like this (nothing wrong here) (file is accessible by php) : 我附上这样的文件(这里没有错)(该文件可通过php访问):

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

Apparently, the file zzz.txt could not be found in the current directory, you should specify it's location either absolute or relative, for example, using the __DIR__ constant: 显然,在当前目录中找不到文件zzz.txt ,您应该使用__DIR__常量指定其绝对或相对位置。

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

For reference, see http://php.net/manual/en/language.constants.predefined.php . 作为参考,请参见http://php.net/manual/zh/language.constants.predefined.php

It's works good for me. 对我来说很好。 Try the following code 试试下面的代码

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)));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM