gpt4 book ai didi

php - 代码点火器 : Sendmail cannot use Mailgun\Mailgun - it is not a trait Composer

转载 作者:搜寻专家 更新时间:2023-10-31 21:19:25 24 4
gpt4 key购买 nike

我尝试用图书馆发送电子邮件Mailgun在 Codeigniter 中使用 composer 安装。我收到一些错误:

Fatal error: Sendmail cannot use Mailgun\Mailgun - it is not a trait in C:\xampp\htdocs\ngetest\application\controllers\Sendmail.php on line 4
A PHP Error was encountered
Severity: Error

Message: Sendmail cannot use Mailgun\Mailgun - it is not a trait

Filename: controllers/Sendmail.php

Line Number: 4

Backtrace:

我不知道为什么会出现此错误,我已经关注文档 mailgun 并观看了 youtube,但仍然出现此错误。

我的配置 Codeigniter 是:

我的 Sendmail Controller

<?php
class Sendmail extends CI_Controller
{
use Mailgun\Mailgun;
public function __construct()
{
parent::__construct();
# Include the Autoloader (see "Libraries" for install instructions)
// require FCPATH . './vendor/autoload.php';
}
public function index()
{

try {
# Instantiate the client.
$mgClient = new Mailgun('1xxxx');
$domain = "xxx.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage($domain, array(
'from' => 'Excited User <mailgun@YOUR_DOMAIN_NAME>',
'to' => 'Baz <YOU@YOUR_DOMAIN_NAME>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!'
));
return $result;
} catch (\Throwable $th) {
echo ' $th';
}
}
}

最佳答案

我认为问题出在您的use Mailgun\Mailgun;。这必须在文件的开头,在您声明类之前:

<?php

use Mailgun\Mailgun;

class Sendmail extends CI_Controller
{
...

类内的 use 与类外的处理方式不同。

供引用:

关于php - 代码点火器 : Sendmail cannot use Mailgun\Mailgun - it is not a trait Composer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57735896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com