public function __construct($group = false) { parent::__construct(); $isSMTP = !isset($group['isSMTP']) ? MAIL_IS_SMTP : $group['isSMTP']; $smtpAuth = !isset($group['smtpAuth']) ? MAIL_SMTP_AUTH : $group['smtpAuth']; $isHTML = !isset($group['isHTML']) ? MAIL_IS_HTML : $group['isHTML']; $charset = !isset($group['charset']) ? MAIL_CHARSET : $group['charset']; $smtpSecure = !isset($group['smtpSecure']) ? MAIL_SMTP_SECURE : $group['smtpSecure']; $host = !isset($group['host']) ? MAIL_HOST : $group['host']; $port = !isset($group['port']) ? MAIL_PORT : $group['port']; $user = !isset($group['user']) ? MAIL_USER : $group['user']; $pass = !isset($group['pass']) ? MAIL_PASS : $group['pass']; $this->isSMTP(); // Set mailer to use SMTP $this->Host = $host; // Specify main and backup SMTP servers $this->SMTPAuth = $smtpAuth; // Enable SMTP authentication $this->Username = $user; // SMTP username $this->Password = $pass; // SMTP password $this->SMTPSecure = $smtpSecure; // Enable TLS encryption, `ssl` also accepted $this->Port = $port; // TCP port to connect to $this->isHTML($isHTML); // Set email format to HTML $this->CharSet = $charset; }
/** * Отправка писем. * @return Boolean */ public function sendMail($subject, $message, $allMails = true) { if ($allMails == true) { $this->addMails(); } $mail = new PhpMailer(); $mail->IsMAIL(); $mail->CharSet = "utf-8"; $mail->From = $this->config->fromMail; $mail->FromName = $this->config->fromName; $mail->Host = "localhost"; $mail->Subject = $subject; foreach ($this->_mails as $to) { $mail->AddAddress($to); } $mail->IsHTML(0); $mail->Body = $message; $mail->Send(); $mail->ClearAddresses(); return true; }
public function __construct($param = false) { parent::__construct(); if (!isset($param['type']) or isset($param['type']) && $param['type'] == 'smtp') { //$isSMTP = (!isset($param['isSMTP'])) ? MAIL_IS_SMTP : $param['isSMTP']; $smtpAuth = !isset($param['smtpAuth']) ? MAIL_SMTP_AUTH : $param['smtpAuth']; $isHTML = !isset($param['isHTML']) ? MAIL_IS_HTML : $param['isHTML']; $charset = !isset($param['charset']) ? MAIL_CHARSET : $param['charset']; $smtpSecure = !isset($param['smtpSecure']) ? MAIL_SMTP_SECURE : $param['smtpSecure']; $host = !isset($param['host']) ? MAIL_HOST : $param['host']; $port = !isset($param['port']) ? MAIL_PORT : $param['port']; $user = !isset($param['user']) ? MAIL_USER : $param['user']; $pass = !isset($param['pass']) ? MAIL_PASS : $param['pass']; //Making an SMTP connection with authentication. $this->Mailer = 'smtp'; // Set mailer to use SMTP $this->Host = $host; // Specify main and backup SMTP servers $this->SMTPAuth = $smtpAuth; // Enable SMTP authentication $this->Username = $user; // SMTP username $this->Password = $pass; // SMTP password $this->SMTPSecure = $smtpSecure; // Enable TLS encryption, `ssl` also accepted $this->Port = $port; // TCP port to connect to $this->isHTML($isHTML); // Set email format to HTML $this->CharSet = $charset; } else { if (isset($param['type']) && $param['type'] == 'sendmail') { //Sending a message using a local sendmail binary. $this->Mailer = 'sendmail'; } else { if (isset($param['type']) && $param['type'] == 'mail' or $param['type'] == 'php') { //Send messages using PHP's mail() function. $this->Mailer = 'mail'; } } } //Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages //$this->SMTPDebug = 2; //$this->Debugoutput = 'html'; }
public function bcc($addresses, $name = '') { if (!is_array($addresses)) { $this->phpMailer->AddBCC($addresses, $name); } else { foreach ($addresses as $address) { if (is_array($address)) { $sendAddress = $address[0]; $name = $address[1]; } else { $sendAddress = $address; $name = ''; } $this->phpMailer->AddBCC($sendAddress, $name); } } return $this; }
public function Ready($subject, $message, $address, $priority, $attachFilePath = null) { $exito = false; $mailer = new PhpMailer(); $mailer->IsSMTP(); $mailer->Host = Yii::app()->params['mailHost']; $mailer->SMTPAuth = Yii::app()->params['mailSMTPAuth']; $mailer->Username = Yii::app()->params['mailUsername']; $mailer->Password = Yii::app()->params['mailPassword']; $mailer->From = Yii::app()->params['mailSenderEmail']; $mailer->FromName = Yii::app()->params['mailSenderName']; $mailer->CharSet = 'UTF-8'; $mailer->AltBody = 'To view the message, please use an HTML compatible email viewer!'; if (isset($address['email']) && isset($address['name'])) { $mailer->AddAddress($address['email'], $address['name']); } else { for ($i = 0; $i < count($address); $i++) { $mailer->AddBCC(str_replace('"', '', $address[$i]), str_replace('"', '', $address[$i])); } } $mailer->Subject = $subject; $mailer->Body = $message; if ($attachFilePath != null) { $mailer->AddAttachment($attachFilePath); } $exito = $mailer->Send(); if (!$exito) { $cabeceras = 'From: ' . Yii::app()->params['mailSenderEmail'] . "\r\n" . 'Reply-To: ' . Yii::app()->params['mailSenderEmail'] . "\r\n" . 'X-Mailer: PHP/' . phpversion() . "\r\n"; $cabeceras .= 'MIME-Version: 1.0' . "\r\n"; $cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $exito = mail($address['email'], $subject, $message, $cabeceras); if (isset($address['email']) && isset($address['name'])) { $exito = mail($address['email'], $subject, $message, $cabeceras); } else { for ($i = 0; $i < count($address); $i++) { $exito = mail(str_replace('"', '', $address[$i]), $subject, $message, $cabeceras); } $exito = true; } } $mailer->ClearAddresses(); return $exito; }
/** * Send * * @return none - sends the email. */ public function send() { $this->AltBody = strip_tags(stripslashes($this->Body)) . "\n\n"; $this->AltBody = str_replace(" ", "\n\n", $this->AltBody); return parent::send(); }
/** * @expectedException Apix\Log\Exception * This test relies on the mailer not being usable - for example that it uses an unreachable host */ public function testThrowsExceptionOnPhpMailerError() { $logger = new PhpMailer($this->mailer); $logger->info("Log me!"); }
/** * @param UserModel $user * @param EmailModel $emailModel * @param array $variables * @throws Exception * @return bool */ private function _sendEmail(UserModel $user, EmailModel $emailModel, $variables = array()) { // Get the saved email settings. $emailSettings = $this->getSettings(); if (!isset($emailSettings['protocol'])) { throw new Exception(Craft::t('Could not determine how to send the email. Check your email settings.')); } $email = new \PhpMailer(true); // Default the charset to UTF-8 $email->CharSet = 'UTF-8'; // Add a reply to (if any). Make sure it’s set before setting From, because email is dumb. if (!empty($emailModel->replyTo)) { $email->AddReplyTo($emailModel->replyTo); } // Set the "from" information. $email->SetFrom($emailModel->fromEmail, $emailModel->fromName); // Check which protocol we need to use. switch ($emailSettings['protocol']) { case EmailerType::Gmail: case EmailerType::Smtp: $this->_setSmtpSettings($email, $emailSettings); break; case EmailerType::Pop: $pop = new \Pop3(); if (!isset($emailSettings['host']) || !isset($emailSettings['port']) || !isset($emailSettings['username']) || !isset($emailSettings['password']) || StringHelper::isNullOrEmpty($emailSettings['host']) || StringHelper::isNullOrEmpty($emailSettings['port']) || StringHelper::isNullOrEmpty($emailSettings['username']) || StringHelper::isNullOrEmpty($emailSettings['password'])) { throw new Exception(Craft::t('Host, port, username and password must be configured under your email settings.')); } if (!isset($emailSettings['timeout'])) { $emailSettings['timeout'] = $this->_defaultEmailTimeout; } $pop->authorize($emailSettings['host'], $emailSettings['port'], $emailSettings['timeout'], $emailSettings['username'], $emailSettings['password'], craft()->config->get('devMode') ? 1 : 0); $this->_setSmtpSettings($email, $emailSettings); break; case EmailerType::Sendmail: $email->IsSendmail(); break; case EmailerType::Php: $email->IsMail(); break; default: $email->IsMail(); } // If they have the test email config var set to something, use it instead of the supplied email. if (($testToEmail = craft()->config->get('testToEmailAddress')) != '') { $email->AddAddress($testToEmail, 'Test Email'); } else { $email->AddAddress($user->email, $user->getFullName()); } // Add any BCC's if (!empty($emailModel->bcc)) { foreach ($emailModel->bcc as $bcc) { if (!empty($bcc['email'])) { $bccEmail = $bcc['email']; $bccName = !empty($bcc['name']) ? $bcc['name'] : ''; $email->AddBcc($bccEmail, $bccName); } } } // Add any CC's if (!empty($emailModel->cc)) { foreach ($emailModel->cc as $cc) { if (!empty($cc['email'])) { $ccEmail = $cc['email']; $ccName = !empty($cc['name']) ? $cc['name'] : ''; $email->AddCc($ccEmail, $ccName); } } } // Add a sender header (if any) if (!empty($emailModel->sender)) { $email->Sender = $emailModel->sender; } // Add any string attachments if (!empty($emailModel->stringAttachments)) { foreach ($emailModel->stringAttachments as $stringAttachment) { $email->AddStringAttachment($stringAttachment['string'], $stringAttachment['fileName'], $stringAttachment['encoding'], $stringAttachment['type']); } } // Add any normal disc attachments if (!empty($emailModel->attachments)) { foreach ($emailModel->attachments as $attachment) { $email->AddAttachment($attachment['path'], $attachment['name'], $attachment['encoding'], $attachment['type']); } } $variables['user'] = $user; $email->Subject = craft()->templates->renderString($emailModel->subject, $variables); // If they populated an htmlBody, use it. if ($emailModel->htmlBody) { $renderedHtmlBody = craft()->templates->renderString($emailModel->htmlBody, $variables); $email->MsgHTML($renderedHtmlBody); $email->AltBody = craft()->templates->renderString($emailModel->body, $variables); } else { // They didn't provide an htmlBody, so markdown the body. $renderedHtmlBody = craft()->templates->renderString(StringHelper::parseMarkdown($emailModel->body), $variables); $email->MsgHTML($renderedHtmlBody); $email->AltBody = craft()->templates->renderString($emailModel->body, $variables); } if (!$email->Send()) { throw new Exception(Craft::t('Email error: {error}', array('error' => $email->ErrorInfo))); } return true; }
/** * Löscht abgelaufene Dateien */ public function removeExpiredShares() { $buffer_days = 15; $medien = Medien::filter(array('share' => 1)); $send = false; $nachricht = "Folgende abgelaufene Dateien wurden automatisch gelöscht: \n\n"; foreach ($medien as $medium) { $invalid = strtotime($medium->me_valid_until); if (strtotime("+" . $buffer_days . "days", $invalid) < time()) { $nachricht .= $medium->me_titel . "\n"; $medium->delete(); $send = true; } } if ($send) { $empfaenger = Configuration::get('mail.shareInfo'); $betreff = '[' . Configuration::get('site.title') . '] Geteilte Dateien wurden gelöscht'; return PhpMailer::getInstance()->sendMail($empfaenger, $betreff, $nachricht); } }