Codeigniter将电子邮件发送到多个电子邮件ID,文件附件不随电子邮件一起发送 [英] Codeigniter sending email to multiple email ids, file attachment is not going with emails
本文介绍了Codeigniter将电子邮件发送到多个电子邮件ID,文件附件不随电子邮件一起发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过表单向具有附件的多个用户发送电子邮件,在表单中,我正在选择电子邮件ID并附加一个文件。电子邮件正在发送,但没有附加文件,而文件正在给定目录中上载。我认为路径存在问题,请提供帮助。
I am trying to send email to multiple users with an attachment through a form, In the form,I am selecting email id's and attaching a single file. Emails are going but without the file attached, while file is uploading in the given directory. I think there is some problem with the path, Please help.
class Email extends MY_Controller
{
public function __construct() {
parent::__construct();
$this->load->model('global_model');
$this->load->library('email');
if(!$this->_is_logged_in('admin_id'))
{
_redirect('admin_login');
}
}
public function send_newsletter()
{
$config = [
'upload_path' => './assets/email_documents',
'allowed_types' => 'jpg|gif|png|jpeg|doc|docx|pdf|xls|xlsx|ppt|pptx|txt',
'max_size' => '5120',
];
$this->load->library('upload', $config);
$this->upload->do_upload('filename');
$data = $this->upload->data(); // To Upload the image
$file_name = $data['file_name']."<br/>";
$file_path = base_url("assets/email_documents/" . $data['raw_name'] . $data['file_ext']);
$lists = $this->input->post('lists');
$subject = $this->input->post('subject');
//$message = $this->input->post('message');
$join_str1 = "subscribers.subscriber_list_id=lists.list_id";
$subscribers =
$this->global_model
->join_2table('subscribers','lists', $join_str1,['subscriber_list_id'=>$lists,'subscriber_status'=>'Active']);
foreach($subscribers as $row) {
$email_lists = $row['subscriber_email'];
$random_key = $row['random_key'];
$message = $this->input->post('message').
"<a href=\"http://example.com/crm_alazizi/unsubscribe/unsubscribe_me/{$random_key}\">Unsubscribe Here</a>";
$from_email = 'support@example.com';
$this->email->from($from_email, 'CRM ALAZIZI');
$this->email->to($email_lists);
$this->email->subject($subject);
$this->email->message($message);
$this->email->set_mailtype('html');
$this->email->attach('/assets/email_documents/'.$file_name);
$sendmail = $this->email->send();
}
//Send mail
if($sendmail)
{
$this->session->set_flashdata('msg','Email sent successfull.');
_redirect_pre();
}
else
{
$this->session->set_flashdata('msg','Email sent Unsuccessfull,Please try again');
_redirect_pre();
}
}
推荐答案
long射击:
更改
$this->email->attach('/assets/email_documents/'.$file_name);
到
$this->email->attach(base_url .'assets/email_documents/'.$file_name);
您说的文件正确上传,可能是文件名错误:
As you say the file uploads correctly, maybe the file name is wrong:
来自
$file_name = $data['file_name']."<br/>";
$file_path = base_url("assets/email_documents/" . $data['raw_name'] . $data['file_ext']);
到
$file_name = $data['raw_name'] . $data['file_ext'];
$file_path = base_url("assets/email_documents/" . $file_name);
如果投票失败,我将删除它,我会很快尝试。
If it gets downvoted I'll delete, I just tried quickly.
这篇关于Codeigniter将电子邮件发送到多个电子邮件ID,文件附件不随电子邮件一起发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文