我正在尝试通过email_model中的电子邮件功能发送电子邮件,但未发送电子邮件
class email_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function email($name) {
$this->db->select('*');
$this->db->from('dna_crm_emails');
$this->db->where('email_name',$name);
$query = $this->db->get();
return $query->result();
}
}
非常感谢任何参考或帮助。
此致
答案 0 :(得分:0)
email_model中的电子邮件功能只是在给定的email_name上检索数据
你需要的是通过邮件类发送邮件Mudshark
提到
你需要在controller
创建一个函数,它会是这样的:
function sendMail($sender_email, $sender_name, $target_email, $subject, $message_data) {
$this -> load -> library('email');
// whatever email you want it to be as a sender
//just make sure it end with your domain name to not get blocked
// ex : 'noreply@yourdomain.com','Support'
$this -> email -> from($email, $sender);
$this -> email -> to($target_email);//the email you're targeting
$this -> email -> subject($subject); // message subject
$message = "This is message data : ". $message_data;
$this -> email -> message($message); // message body as plain text
$this -> email -> send();
}
您可以使用更高级的选项,例如将邮件发送为html,方法是为您的电子邮件消息创建一个带有设计html的视图message.php
,并为其解析一组数据。
你的功能是这样的:
function sendMail($sender_email, $sender_name, $target_email, $subject, $message_data) {
$this -> load -> library('email');
$config['mailtype'] = 'html';
$this -> email -> initialize($config); // to define email as html type
$this -> email -> from($email, $sender);
$this -> email -> to($target_email);//the email you're targeting
$this -> email -> subject($subject); // message subject
$this->email->message( $this->load->view( 'message', $message_data, true )); //html message
$this -> email -> send();
}