我在Codeigniter中使用"电子邮件"库发送电子邮件时遇到问题。
这是错误:
A PHP Error was encountered
Severity: Warning
Message: mail() expects parameter 1 to be string, array given
Filename: libraries/Email.php
Line Number: 1553
这是我的代码,im发送电子邮件请求的模型。
$count = count($result);
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => $correo, // change it to yours
'smtp_pass' => '', // change it to yours
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "'r'n",
'wordwrap' => TRUE
);
$body = "¡Hola! <br><br>";
$body .= "Este e-mail es para avisarte que has recibido un nuevo m ensaje " . $contexto . $result2[0]->nombre . ".<br><br>";
$body .= "Contenido: <strong>" . $mensaje . ".<strong><br>";
if ($tipo == 2) {
$body .= "Entra a la aplicación Para confirmar tu asistencia.";
}
$this->load->library('Email');
$this->load->library('Email', $config);
$this->email->set_mailtype("html");
$this->email->from($correo);
for ($i = 0; $i < $count; $i++) {
foreach ($result[$i] as $item) {
$this->email->to($item);
}
}
$this->email->subject($asunto);
$this->email->message($body);
$this->email->send();
}
}
我不知道为什么要发送此错误。不感谢任何帮助。
我知道
如果你不指定任何接收器($this->email->to),你可能会遇到问题,比如你的..你确定你的$count变量大于0吗?您可以尝试没有循环,只需发送到任何电子邮件地址以检查是否有效吗?