简体   繁体   English

我正在在Codeigniter中发送带有发送网格的附件邮件

[英]I am sending attachment mail with send grid in codeigniter

I am sending attachment mail with send grid in codeigniter . 我正在使用codeigniter中的send grid发送附件邮件。 Mail send successfully But attachment file could not show after download . 邮件发送成功,但下载后无法显示附件文件。 my code:- 我的代码:

public function test() {
            $attach = base_url()."/uploads/a.png";
            $this->SendMail('asheesh9308@gmail.com', 'asheesh9308@gmail.com', 'sss sub', 'ss msg',$attach, 'dss.png');

        }

Send grid API 发送网格API

function SendMail($from, $email, $subject, $message, $attach = '', $filename = '') 
 {
       $url = 'https://api.sendgrid.com/';
       $user = 'XXXXXX';
       $pass = 'XXXXXX';

       if ($attach <> '' && $filename <> '') {

        $params = array(
                        'api_user' => $user,
                        'api_key' => $pass,
                        'to' => $email,
                        'fromname' => $from,
                        'from' => $from,
                        'subject' => $subject,
                        'html' => $message,
                        'files[' . $filename . ']' => new \CurlFile($attach),
                           'files[' . $filename . ']' => '@' . $attach,
                    );
        } else {

                $params = array(
                        'api_user' => $user,
                        'api_key' => $pass,
                        'to' => $email,
                        'fromname' => $from,
                        'from' => $from,
                        'subject' => $subject,
                        'html' => $message);
        }
        $request = $url . 'api/mail.send.json';
        $session = curl_init($request);
        curl_setopt($session, CURLOPT_POST, true);
        curl_setopt($session, CURLOPT_POSTFIELDS, $params);
        curl_setopt($session, CURLOPT_HEADER, false);
        // Tell PHP not to use SSLv3 (instead opting for TLS)
       //curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
       curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
       // obtain response
       $response = curl_exec($session);
        curl_close($session);
                return true; 
}

You need attach file differently, passing more parameters into Curlfile constructor like 您需要以不同方式附加文件,将更多参数传递给Curlfile构造函数,例如

new CurlFile('filename.png', 'image/png', 'filename.png')

Check these links a and b 检查这些链接ab

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

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