Exemple #1
0
/**
 * utils.php   file.
 *
 * Collection of utility functions
 * @author Miguel Sanchez <*****@*****.**>
 */
function sendHtmlEmail($toStr, $subject, $content, $ccStr = null)
{
    /* ini_set("SMTP", "mailserver.copservir.com");
        ini_set("smtp_port", "25");
        ini_set("sendmail_from", "mailserver.copservir.com");
        Yii::import('application.extensions.phpmailer.JPhpMailer');
        $mail = new JPhpMailer;
        $mail->isSMTP();
        $mail->Host = 'mailserver.copservir.com';
        $mail->Port = 25;
        $mail->SMTPAuth = false;
        $mail->isHTML(true);
        $mail->CharSet = "UTF-8";
       */
    Yii::import('application.extensions.phpmailer.JPhpMailer');
    $mail = new JPhpMailer();
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->Username = '******';
    $mail->Password = '******';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 587;
    $mail->isHTML(true);
    $mail->CharSet = "UTF-8";
    $mail->From = Yii::app()->params->correoAdmin;
    $mail->FromName = Yii::app()->name;
    if ($toStr === null) {
        throw new Exception("email receiver is empty");
    }
    $toStr = trim($toStr);
    if (empty($toStr)) {
        throw new Exception("email receiver is empty");
    }
    $toArr = explode(",", $toStr);
    if (empty($toArr)) {
        throw new Exception("email receiver is empty");
    }
    foreach ($toArr as $to) {
        $mail->addAddress($to);
    }
    if ($ccStr !== null) {
        $ccArr = explode(",", $ccStr);
        foreach ($ccArr as $cc) {
            $mail->addCC($cc);
        }
    }
    $mail->Subject = $subject;
    $mail->Body = $content;
    if (!$mail->send()) {
        throw new Exception("Message could not be sent. " . $mail->ErrorInfo);
    }
}