通过循环提交电子邮件时遇到问题。我得到了 html 和纯文本格式的不同用户名。
这是我的控制器功能报告(){
$this->load->model('Searchmonitoring_db');
$results = $this->Searchmonitoring_db->getLogs();
if (!$results)
return false;
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
foreach ($results as $result) {
$fname = $result['fname'];
$username = $result['username'];
$subject_keyword = $result['grpname'];
if ($subject_keyword == "") {
$findfields['clientid'] = $result['clientid'];
$findfields['grouping'] = $result['grouping'];
$keywords = $this->Searchmonitoring_db->getKeywords($findfields);
if ($keywords['db']) {
foreach ($keywords['db'] as $kw) {
if ($subject_keyword != "")
$subject_keyword .= ", ";
$subject_keyword .= $kw['query'];
}
}
}
$this->email->clear(TRUE);
$managerEmail = $result['manager_email'];
$manager = $result['manager'];
$salespersonEmail = $result['salesperson_email'];
$salesperson = $result['salesperson'];
$clientEmail = $result['email'];
if($managerEmail) {
$this->email->from($managerEmail, $manager);
} elseif($salespersonEmail) {
$this->email->from($salespersonEmail, $salesperson);
}
$this->email->to($clientEmail);
$arrfname = explode("/", $fname);
$subject = "Your $subject_keyword monitoring report";
$this->email->subject($subject);
$message = $this->load->view('emailtemplate', $result, true);
$this->email->message($message);
$this->email->attach("../export/$username/" . end($arrfname) . ".zip");
if ($this->email->send()) {
$update['id'] = $result['logid'];
$searchlog['result'] = 'Sent';
$this->Searchmonitoring_db->updateLog($update, $searchlog);
}
}
}
这是我的电子邮件模板
<html>
<body>
<p>Hi <?php echo $firstname; ?></p>
<p>Thanks for your business!</p>
<p>
<?php
if($manager) {
echo nl2br($manager_email_signature);
} elseif($salesperson) {
echo nl2br($salesperson_email_signature);
} ?>
</p>
</body>
</html>
我还使用邮戳来监视我的电子邮件,当我单击电子邮件时,html 格式会得到正确的名称,但是当我单击纯文本格式时,它的名称会不正确。
示例: html:说“嗨,杰克,感谢您的业务”。纯文本:说“嗨,安德森,感谢您的业务”。
我注意到纯文本在循环中获取第一封电子邮件的名称