dongyoulou4829 2019-05-07 02:21
浏览 135
已采纳

如何使用PHPMailer将QRCode发送到Gmail(CodeIgniter 3)

I have some script Codeigniter where user want to register and the qrcode is send to user's gmail. But, how to send that? the variable is $mailContent

This is my code

        $name = $this->input->post('name');
        $email = $this->input->post('email');
        $no_hp = $this->input->post('no_hp');
        $gen = $this->input->post('gen');
        $method = $this->input->post('method');

        $this->load->library('ciqrcode');

        $config['cacheable']    = true; //boolean, the default is true
        $config['cachedir']     = './assets/'; //string, the default is application/cache/
        $config['errorlog']     = './assets/'; //string, the default is application/logs/
        $config['imagedir']     = './assets/images/'; 
        $config['quality']      = true; //boolean, the default is true
        $config['size']         = '1024'; //interger, the default is 1024
        $config['black']        = array(224,255,255); // array, default is array(255,255,255)
        $config['white']        = array(70,130,180); // array, default is array(0,0,0)
        $this->ciqrcode->initialize($config);

        $image_name=$name.'.png'; 

        $params['data'] = $name; 
        $params['level'] = 'H'; //H=High
        $params['size'] = 10;
        $params['savename'] = FCPATH.$config['imagedir'].$image_name; 
        $this->ciqrcode->generate($params); 

        //PHP Mailer
        // Load PHPMailer library
        $this->load->library('phpmailer_lib');

        // PHPMailer object
        $mail = $this->phpmailer_lib->load();

        // SMTP configuration
        $mail->isSMTP();
        $mail->Host     = 'smtp.gmail.com';
        $mail->SMTPAuth = true;
        $mail->Username = 'xxxxx@gmail.com';
        $mail->Password = '******';
        $mail->SMTPSecure = 'tls';
        $mail->Port     = 587;

        $mail->setFrom('xxxxx@gmail.com', 'RyanK');
        $mail->addReplyTo('xxxxx@gmail.com', 'RyanK');

        // Add a recipient
        $mail->addAddress($email);

        // Add cc or bcc 
        $mail->addCC('cc@example.com');
        $mail->addBCC('bcc@example.com');

        // Email subject
        $mail->Subject = 'Send Email via SMTP using PHPMailer in CodeIgniter';

        // Set email format to HTML
        $mail->isHTML(true);

        // Email body content
        $mailContent = "<h1>Send HTML Email using SMTP in CodeIgniter</h1>
            <p></p>";
        $mail->Body = $mailContent;

        // Send email
        if(!$mail->send()){
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        }else{
            echo 'Message has been sent';
        }
  • 写回答

1条回答 默认 最新

  • 普通网友 2019-05-07 11:45
    关注

    You're already using it to set the Body property in $mail->Body = $mailContent;. To add an image from an external file:

    $mail->addAttachment('path/to/file.png');
    

    If your QR code generator creates a binary string containing PNG data, use addStringAttachment:

    $mail->addStringAttachment($imagedata, 'QR code.png');
    

    Alternatively you might want to embed it and create a reference to it that you can use in your message body using addStringEmbeddedImage.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?