gpt4 book ai didi

php - 在codeigniter中发送电子邮件

转载 作者:行者123 更新时间:2023-12-04 06:25:06 27 4
gpt4 key购买 nike

是否可以从临时目录发送附件?
当我发送邮件时,我收到了 print_r($_FILES)作为

Array ( [file] => Array ( [name] => test.doc 
[type] => application/msword
[tmp_name] => /tmp/php2UaLKE
[error] => 0 [size] => 681472 )
)

我的错误是无法找到以下电子邮件附件: /tmp/php2UaLKE/EasyToEat.doc

我的声明如下:
$attachment=$_FILES['file']['tmp_name'].'/'.$_FILES['file']['name'];        
$this->email->attach($attachment);

我想知道是否可以将文档附加到邮件而不将其上传到 codeigniter 中服务器上的指定位置?

最佳答案

我实际上只是这样做了......它比你需要的多一点,但它确实做到了。将文件写入临时目录,然后通过电子邮件发送。


function send_weekly_report()
{
$server_ip = $_SERVER['REMOTE_ADDR'];
if($server_ip != '127.1.1.1')
{
$this->load->model('admin_model');
$this->load->helper('csv_helper');
$this->load->helper('file');
//create CSV Array
$header = array("Sales Rep", "Client", "Action Taken", "Won or Lost", "Action Why", "Current Vendor", "Comp. Cal Program", "Comp. Cal Date", "Notes", "Time");
$data = $this->admin_model->load_week();
$output = array_merge(array($header), $data);

$csv = array_to_csv($output);
$filename = '/tmp/'.time().".csv";
if ( ! write_file($filename, $csv))
{
$this->load->library('email');
$this->email->from('donotreply@email', 'Admin');
$this->email->to('peter@email.com');

$this->email->subject('Weekly Sales Test FAIL!!!!!');
$this->email->message('Weekly Report Failed!');
$this->email->send();
}
else
{
//send email
$this->load->library('email');
$this->email->from('donotreply@email', 'Admin');
$this->email->to('peter@email.com');

$this->email->subject('Weekly Sales Test');
$this->email->message('Please find the attached report.');
$this->email->attach($filename);
$this->email->send();

//echo $this->email->print_debugger();
}

}
}

关于php - 在codeigniter中发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6134857/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com