如何使用 PHPMailer (CodeIgniter 3) 发送二维码到 Gmail

How to Send QRCode to Gmail Using PHPMailer (CodeIgniter 3)

我有一些脚本 Codeigniter,用户想在其中注册并将二维码发送到用户的 gmail。但是,如何发送?变量是 $mailContent

这是我的代码

        $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';
        }

您已经在使用它在 $mail->Body = $mailContent; 中设置 Body 属性。要从外部文件添加图像:

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

如果您的二维码生成器创建了包含 PNG 数据的二进制字符串,请使用 addStringAttachment:

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

或者,您可能希望嵌入它并创建对它的引用,您可以使用 addStringEmbeddedImage.

在邮件正文中使用该引用