简体   繁体   中英

Error sending email with codeigniter

Im having a lil problem sending an email with 'Email' library in Codeigniter.

This is the error:

A PHP Error was encountered
Severity: Warning
Message:  mail() expects parameter 1 to be string, array given
Filename: libraries/Email.php
Line Number: 1553

Here my code, the model where im sending the email request.

 $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();
}

}

I dont know why is sending this error. Ill appreciate any help.

I know that if you don't specify any receiver ($this->email->to), you can have problem such as your.. are you sure that your $count variable is bigger than 0 ? can you try without your loop for and just send to any email address to check if works ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM