【发布时间】:2020-07-26 22:44:32
【问题描述】:
我需要什么:我需要使用 Sendgrid API 密钥从 Codeigniter 发送一封电子邮件。
我在下面展示了使用 SMTP 详细信息以及 codeigniter 中的用户名和密码发送电子邮件的示例。
例子:
在 application/config 文件夹中创建一个名为“email.php”的文件,并将以下代码粘贴到其中。
/* application/config/email.php */
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| SendGrid Setup
|--------------------------------------------------------------------------
|
| All we have to do is configure CodeIgniter to send using the SendGrid
| SMTP relay:
*/
$config['protocol'] = 'smtp';
$config['smtp_port'] = '587';
$config['smtp_host'] = 'smtp.sendgrid.net';
$config['smtp_user'] = 'yourusername';
$config['smtp_pass'] = 'yourpassword';
?>
在控制器中:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->library('email');
$this->email->from('test123@gmail.com', 'John');
$this->email->to('test123@gmail.com');
$this->email->subject('Test Email using SendGrid');
$this->email->message('This email was delivered by your friends at SendGrid');
$this->email->send();
echo $this->email->print_debugger();
$this->load->view('welcome_message');
}
}
?>
但我需要通过 API 密钥发送邮件。有没有可能做的。
谢谢
【问题讨论】:
-
你试过这个库了吗github.com/sendgrid/sendgrid-php
-
@MohammedShafeek 是的,我直接在 PHP 中尝试它工作正常。但我不知道如何在 codeigniter 中进行设置。如果你知道,请帮我解决这个问题。
标签: php codeigniter sendgrid-api-v3