protected function execute($arguments = array(), $options = array()) { $con = $this->crearConexion(); try { $record = Doctrine::getTable('EmailConfiguration')->findAll()->getFirst(); $config_mail = array('charset' => 'UTF-8', 'encryption' => $record->getSmtpSecurityType(), 'host' => $record->getSmtpHost(), 'port' => $record->getSmtpPort(), 'username' => $record->getSmtpUsername(), 'password' => $record->getSmtpPassword(), 'authentication' => $record->getSmtpAuthType()); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet = $config_mail['charset']; if ($config_mail['authentication'] == "login") { $mail->SMTPAuth = true; } if ($config_mail['encryption'] == "tls") { $mail->SMTPSecure = "tls"; } if ($config_mail['encryption'] == "ssl") { $mail->SMTPSecure = "ssl"; } $mail->Host = $config_mail['host']; $mail->Port = $config_mail['port']; $mail->Username = $config_mail['username']; $mail->Password = $config_mail['password']; $mail->FromName = 'Mi company'; $mail->From = $config_mail['username']; //email de remitente desde donde se env?a el correo $mail->AddAddress($config_mail['username'], 'Destinatario'); //destinatario que va a recibir el correo $mail->Subject = "confeccion de gafete"; /*Recojemos los datos del oficial*/ $dao = new EmployeeDao(); $employeeList = $dao->getEmployeeList(); foreach ($employeeList as $employee) { if ($employee->getJoinedDate() != "") { $datetime1 = new DateTime($employee->getJoinedDate()); $datetime2 = new DateTime(date('y-m-d', time())); $formato = $datetime2->format('y-m-d'); $intervalo = $datetime1->diff($datetime2, true); if ($intervalo->m == 2 && $intervalo->d == 0) { $html = "Identificador: " . $employee->getEmployeeId() . "<br/>"; $html .= "ID: " . $employee->getOtherId() . "<br/>"; $html .= "Nombre : " . utf8_encode($employee->getFullName()) . "<br/>"; $html .= "Fecha Nac : " . $employee->getEmpBirthday() . "<br/>"; $sexo = $employee->getEmpGender() == 1 ? "Masculino" : "Femenino"; $html .= "Género : " . $sexo . "<br/>"; $html .= "Nacionalidad: " . $employee->getNationality() . "<br/>"; $html .= "Móvil: " . $employee->getEmpMobile() . "<br/>"; $mail->MsgHTML($html); if (!$mail->Send()) { $this->escribirYML('log_tareas', false, $mail->ErrorInfo . " Error al enviar el correo con los datos del empleado " . $employee->getFullName()); } else { $this->escribirYML('log_tareas', true, "correo enviado con los datos del empleado " . $employee->getFullName()); } } } } Doctrine_Manager::getInstance()->closeConnection($con); } catch (Exception $e) { $this->escribirYML('log_tareas', false, $e->getMessage()); } }
public function SendEmail() { $file = sfConfig::get('sf_app_config_dir') . '/app.yml'; $result = sfYaml::load($file); $config_mail = $result['mailer']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->CharSet = $config_mail['param']['charset']; $mail->SMTPAuth = true; if ($config_mail['param']['tls'] == true) { $mail->SMTPSecure = "tls"; } $mail->Host = $config_mail['param']['host']; $mail->Port = $config_mail['param']['port']; $mail->Username = $config_mail['param']['username']; $mail->Password = $config_mail['param']['password']; $mail->FromName = 'Mi company'; $mail->From = $config_mail['param']['username']; //email de remitente desde donde se env�a el correo $mail->AddAddress($config_mail['param']['username'], 'Destinatario'); //destinatario que va a recibir el correo $mail->Subject = "confección de título"; //$mail->AltBody = 'cuerpo del mensaje en texto plano';//cuerpo con texto plano /*Recojemos los datos del oficial*/ $dao = new EmployeeDao(); $empleoyeeList = $dao->getEmployeeList(); foreach ($empleoyeeList as $employee) { $fecha_union = new DateTime($employee->getJoinedDate()); $fecha_actual = date('yyyy-mm-dd'); $fecha_actual = new DateTime($fecha_actual); $diferencia = $fecha_actual->diff($fecha_union); print_r($diferencia); exit; if ($employee->getJoinedDate()) { } $html = "Identificador: " . $employee->getEmployeeId() . "<br/>"; $html .= "ID: " . $employee->getOtherId() . "<br/>"; $html .= "Nombre : " . $employee->getFullName() . "<br/>"; $html .= "Fecha Nac : " . $employee->getEmpBirthday() . "<br/>"; $sexo = $employee->getEmpGender() == 1 ? "Masculino" : "Femenino"; $html .= "Genero : " . $sexo . "<br/>"; $html .= "Nacionalidad: " . $employee->getNationality() . "<br/>"; $html .= "Movil: " . $employee->getEmpMobile() . "<br/>"; } //print_r($mail->);exit; $mail->MsgHTML($html); //cuerpo con html if (!$mail->Send()) { return false; //print_r($mail->ErrorInfo); } else { return true; } }