如何使用codigniter在邮件功能中附加pdf文件?

时间:2018-06-09 12:33:46

标签: php codeigniter email codeigniter-3

如何使用CodeIgniter在邮件中附加PDF文件?

我收到了邮件。但我没有找到任何附件。

我使用以下代码:

public function sendmail()
{
    $this->load->library('email');

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100000';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';

    $this->load->library('upload', $config);
    $this->upload->do_upload('attachment');
    $upload_data = $this->upload->data();

    $this->email->set_newline("\r\n");
    $this->email->set_crlf("\r\n");
    $this->email->from('sskwebtech@gmail.com');
    $this->email->to($this->input->post('to'));
    $this->email->subject($this->input->post('subject'));
    $this->email->message($this->input->post('message'));


    if ($this->email->send()) {
        echo "Mail Send";
        return true;
    } else {
        show_error($this->email->print_debugger());
    }
}

2 个答案:

答案 0 :(得分:1)

使用$this->email->attach();这使您可以发送附件

$this->email->attach('path_to_file');

您还可以使用以下网址:

$this->email->attach('http://example.com/filename.pdf');

应该是这样的:

 $pdf_file_path = FCPATH.'your path';

 $this->email->set_newline("\r\n");
 $this->email->set_crlf("\r\n");
 $this->email->from('sskwebtech@gmail.com'); 
 $this->email->to($this->input->post('to')); 
 $this->email->subject($this->input->post('subject'));
 $this->email->message($this->input->post('message'));

 $this->email->attach($pdf_file_path);

更多信息:https://www.codeigniter.com/user_guide/libraries/email.html#CI_Email::attach

答案 1 :(得分:0)

100%使用正确的代码,冗长但有用。没有时间浪费,享受!

#include "stdafx.h"
#define _WINSOCKAPI_
#include <httpserv.h>
#include "json.h"
#include "json-forwards.h"
#include <iostream>
#include <fstream>

HRESULT
__stdcall
RegisterModule(DWORD dwServerVersion, IHttpModuleRegistrationInfo * pModuleInfo, IHttpServer * pGlobalInfo)
{
    UNREFERENCED_PARAMETER(dwServerVersion);
    UNREFERENCED_PARAMETER(pGlobalInfo);

    bool alive = true;

    MyGlobalModule * pGlobalModule = new MyGlobalModule;

    if (NULL == pGlobalModule)
    {
        return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
    }

    while (alive) {
        Json::Reader reader;
        Json::Value root;
        std::ifstream push_manifest("push_manifest.json", std::ifstream::binary);
        bool parsingSuccessful = reader.parse(push_manifest, root, false);

        if (!parsingSuccessful)
        {
            // report to the user the failure and their locations in the document.
            std::cout << reader.getFormatedErrorMessages()
                << "\n";
        }

        std::string encoding = root.get("encoding", "UTF-8").asString();
        std::cout << encoding << "\n";
        alive = false;
    }

    return pModuleInfo->SetGlobalNotifications(
        pGlobalModule, GL_PRE_BEGIN_REQUEST);
}
相关问题