因此,我的任务是为我们的成员数据库创建一个函数,它将每月提醒某人他们的成员将在何时到期。我们发出一封电子邮件,如果一个人是6个月或更短的成员到期,另一个如果他们是3个月外。没什么大不了的。我首先创建了这样一个模型:
class Email extends CI_Model {
function __construct()
{
parent::__construct();
}
// -----------------EMAIL-----------------
function emailMessage($message = 1,$recipient = 1777) { // Default "Test" Numbers
$rInfo = $this->db->query("SELECT * FROM Members WHERE intKey = " . $recipient)->row();
$eInfo = $this->db->query("SELECT * FROM Emails WHERE intKey = " . $message)->row();
// Replacements?
$bodyCopy = $eInfo->txtEmail;
$bodyCopy = str_replace("[firstname]",$rInfo->strFirstName,$bodyCopy);
$this->load->library('email');
$this->email->from('someone@example.com','John Q Public');
$this->email->to($rInfo->strEmail);
$this->email->subject($eInfo->strTitle);
$this->email->message($bodyCopy);
$this->email->send();
$this->email->clear();
}
}
一切都很好,当我把这个模型从我所建的网站的任何其他部分调用时,它工作得很好。这是一个很好的方式来处理任何股票电子邮件,必须发送到我们的选区。通常情况下,代码中就是这样的:
$this->load->model('email');
$this->email->emailMessage(8,$this->session->userdata('memberKey'));
就像一种魅力。我以前使用它的地方和现在使用它的位置之间的最大区别是,我在循环中包含了对模型的调用,如下所示:
public function warningEmails() {
$this->load->model('email');
$sql = 'SELECT
*, FLOOR(
DATEDIFF(dtAccreditationEnd, now())/ 30
)AS diff
FROM
tblMembers
WHERE
enmAccredited = "yes"
AND dtAccreditationEnd < DATE_ADD(now(), INTERVAL 6 MONTH)
ORDER BY
diff
';
$emailSend = $this->db->query($sql);
foreach ($emailSend->result() as $row) {
if ($row->diff <= 3) {
$letter = 10;
} else {
$letter = 9;
}
$this->email->emailMessage($letter,$row->intMembersKey);
}
}
它在第一次通过循环时工作得很好,并且在循环的下一次迭代中失败了如下消息:
/home/contract/public_html/members/application/controllers/staff.php中的致命错误:调用未定义的方法CI_Email::emailMessage(),在线1033
第1033行是这一行:
$this->email->emailMessage($letter,$row->intMembersKey);
我有一个问题,这个模型只能在给定的实例中调用一次?我做错了什么?提前感谢您的帮助!
编辑:,我要添加一个var_dump($this->电子邮件);看看它能是什么.
对象(CI_Email)#30 (46) { "useragent"=>字符串(11) "CodeIgniter“”邮件路径“”=> string(18) "/usr/sbin/sendmail“ “协议”=>字符串(4)“邮件"”smtp_host"=>字符串(0)“” "smtp_user"=>字符串(0) "smtp_pass"=> string(0) "“ "smtp_port"=> string(2) "25“"smtp_timeout"=> int(5) "smtp_crypto"=> string(0) "“字包装”=>bool“(True) =>字符串(2) "76“邮件类型”=> string(4)“"text” “字符集”=>字符串(5) "utf-8“”多部分“=>字符串(5)”混合“"alt_message"=> string(0)”验证“=> =>字符串(1) "3“”换行符“=> =>字符串(1) "send_multipart"=> bool(true) "bcc_batch_mode"=> bool(false) "bcc_batch_size"=> int(200) "_safe_mode"=> bool(false) "_subject"=> string(0) "_body"=> string(357) "Geoffrey, 这提醒您的PDCA认证将在3个月内到期。访问您的会员仪表板,查看所有完整和不完整的课程工作在您的方便。会员仪表板将协助您完成过程。欲了解更多信息,请与Someone@example.com或1-800-555-1212联系。"_finalbody"=> string(0) "“ "_alt_boundary"=> string(0) "_atc_boundary"=> string(0) "_header_str"=> string(0) "_smtp_connect"=> 字符串(0) "_encoding"=>字符串(4)“8位"”_IP"=> bool(false) "_smtp_auth"=> bool(false) "_replyto_flag"=> bool(false) "_debug_msg"=>数组(0){} "_recipients"=> 字符串(17) "recipient@example.com“”_cc_array"=>数组(0){} "_bcc_array"=>数组(0){} "_headers"=>数组(5){从“=> string(54)”“某人示例”“返回路径”=> string(28) "Cc"=>字符串(16) "copy@example.com“"Bcc"=> string(17) "blindcopy@example.com”主题“=> string(49) _attach_name”=>数组(0){} "_attach_type"=>数组(0){} "_attach_disp"=>数组(0) "_protocols"=>数组(3){ => string(4)“=>”1=> string(8) "sendmail“2=> string(4) "smtp”}“smtp”=>数组(2){=> string(8) "us-ascii“1=> string(9) "iso-2022”-“}_bit_depths”=>数组(2){ =>字符串(4)“7位”1=>字符串(4)“8位”} "_priorities"=>数组(5){=> string(11) "1 (最高)“1=> string(8) "2 (高)”2=> string(10) "3“(正常值))“3=>字符串(7) "4 (低)”4=>字符串(10)“"5 (最低)”}}
发布于 2012-08-27 18:02:19
尝试将官方电子邮件库重命名为另一个电子邮件库,
$this->load->library('email', NULL, 'ci_email');
然后通过这样做来访问它,
$this->ci_email->from('someone@example.com','John Q Public');
当前的电子邮件库已经覆盖了您的电子邮件模型。
发布于 2012-12-02 22:07:03
我也有类似的症状,但是因为另一个问题。最近,我通过我选择的编辑器将我的模型的文件名从name_model.php更改为Name_model.php,而且我几乎没有意识到我的编辑器实际上并没有删除旧的name_model.php文件,因此两个文件位于目录中,它们的名称和大小写是相同的。
我在我的模型中创建了一个新的函数,但是它正在读取旧的模型文件,这使我耽搁了几个小时,直到我浏览了目录中的实际文件。
只需删除旧文件就能解决我的问题。
发布于 2012-08-27 17:57:34
也许我误解了这句话,但这一行不是:$ this ->load->library('email');
加载写入此行的电子邮件库?我觉得你是在反复自杀。
https://stackoverflow.com/questions/12146266
复制相似问题