sendGrid 邮件功能在 yii

编程入门 行业动态 更新时间:2024-10-21 23:14:28
本文介绍了sendGrid 邮件功能在 yii-framework 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我使用下面的代码作为从我的项目发送邮件的 sendGrid 代码.

I used below code for sendGrid codes for sending mails from my project.

require_once(YII_BASE_PATH . "/lib/sendgrid-php/SendGrid.php");
require_once(YII_BASE_PATH . "/lib/sendgrid-php/SendGrid_loader.php");   
$sendgrid = new SendGrid('uname', 'pwd');
        $mail = new SendGrid\Mail();
        $mail->addTo('xxxxxxxxxx@gmail')->
               setFrom('xxxyyyy5@yahoo.co.in')->
               setSubject('Subject goes here')->
               setText('Hello World!')->
               setHtml('<strong>Hello World!</strong>');
       $sendgrid->smtp->send($mail);

我已经下载了sendGrid包并放到了yii的lib文件夹中.

I already downloaded the sendGrid package and put it into lib folder in yii.

如果我执行上面的代码,我会得到类似 "include(Swift_DependencyContainer.php): failed to open stream: No such file or directory"

if I execute the above code i got error like "include(Swift_DependencyContainer.php): failed to open stream: No such file or directory"

如果我包含了上面的文件,我会收到错误,比如需要包含另一个文件.

if I included the above file i got error like another file need to be include.

请就此提出建议.

推荐答案

最后我让它起作用了.供您参考,我列出了步骤(也为我自己),

finally i make it works. for your reference i list down the steps (for myself also),

1) 我们需要从 https://github/下载 sendgrid-php 包sendgrid/sendgrid-php/downloads

2) 解压文件夹并放置在您的项目文件夹中,如app/mail/".

2) Unzip the folder and placed in your project folder like " app/mail/".

3) 为邮件创建一个 .php 文件,以便在该文件夹中发送邮件,例如app/mail/mail.php".

3) the create one .php file for mail for mail sending in that folder like " app/mail/mail.php ".

4) 在那个文件中,

    <?php
        session_start();
        define("ROOT_DIR", __dir__ . DIRECTORY_SEPARATOR);

        function sendGrid_loader($string) {
            if (preg_match("/SendGrid/", $string)) {
                $file = str_replace('\\', '/', "$string.php");
                require_once ROOT_DIR . $file;
            }
        }

        spl_autoload_register("sendGrid_loader");

        $sendgrid = new SendGrid('sendgrid_username', 'sendgrid_password');
        $mail = new SendGrid\Mail();
    $mail->addTo('foo@bar')->
           setFrom('me@bar')->
           setSubject('Subject goes here')->
           setText('Hello World!')->
           setHtml('<strong>Hello World!</strong>');
?>

5) 当我重定向到 mailsend 页面时,我需要发送邮件.所以我在 Actionmailsend() 的控制器文件中编写代码,

5) i need to send mail when i redirect to mailsend page. so i write code in controller file in Actionmailsend(),

" header("Location:".AT::getUrl()."/mail/mail.php"); ".

只是重定向.就是这样.邮件发送成功.

just redirection. that's it. mail send successfully.

这里是 AT::getUrl() - 用于获取 baseurl.

here AT::getUrl() - used for get baseurl.

它没有集成到 yii 中.我们使用邮件功能将 sendGrid 包文件夹放入 yii 项目文件夹中并使用它.

it's not integrated to yii. we used mail functionality by to place the sendGrid package folder into inside the yii project folder and used it.

这篇关于sendGrid 邮件功能在 yii-framework 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:51:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047634.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:邮件   功能   sendGrid   yii

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!