示例#1
1
 /**
  * Test addressing
  */
 function test_Addressing()
 {
     $this->assertFalse($this->Mail->AddAddress('*****@*****.**'), 'Invalid address accepted');
     $this->assertTrue($this->Mail->AddAddress('*****@*****.**'), 'Addressing failed');
     $this->assertFalse($this->Mail->AddAddress('*****@*****.**'), 'Duplicate addressing failed');
     $this->assertTrue($this->Mail->AddCC('*****@*****.**'), 'CC addressing failed');
     $this->assertFalse($this->Mail->AddCC('*****@*****.**'), 'CC duplicate addressing failed');
     $this->assertFalse($this->Mail->AddCC('*****@*****.**'), 'CC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->AddBCC('*****@*****.**'), 'BCC addressing failed');
     $this->assertFalse($this->Mail->AddBCC('*****@*****.**'), 'BCC duplicate addressing failed');
     $this->assertFalse($this->Mail->AddBCC('*****@*****.**'), 'BCC duplicate addressing failed (2)');
     $this->assertTrue($this->Mail->AddReplyTo('*****@*****.**'), 'Replyto Addressing failed');
     $this->assertFalse($this->Mail->AddReplyTo('*****@*****.**'), 'Invalid Replyto address accepted');
     $this->Mail->ClearAddresses();
     $this->Mail->ClearCCs();
     $this->Mail->ClearBCCs();
     $this->Mail->ClearReplyTos();
 }
示例#2
0
 /**
  * Adds to the "Cc" recipient collection.
  *
  * @param mixed $RecipientEmail An email (or array of emails) to add to the "Cc" recipient collection.
  * @param string $RecipientName The recipient name associated with $RecipientEmail. If $RecipientEmail is
  * an array of email addresses, this value will be ignored.
  * @return Email
  */
 public function Cc($RecipientEmail, $RecipientName = '')
 {
     ob_start();
     $this->PhpMailer->AddCC($RecipientEmail, $RecipientName);
     ob_end_clean();
     return $this;
 }
示例#3
0
 function Send()
 {
     $mail = new PHPMailer();
     $mail->CharSet = 'UTF-8';
     $mail->Host = $this->smtp['smtp_server'];
     $mail->Port = $this->smtp['smtp_port'];
     if ($this->smtp['smtp_enable']) {
         $mail->IsSMTP();
         $mail->Username = $this->smtp['smtp_usr'];
         $mail->Password = $this->smtp['smtp_psw'];
         $mail->SMTPAuth = $this->smtp['smtp_auth'] ? true : false;
     }
     if ($this->smtp['smtp_from_email']) {
         $mail->SetFrom($this->smtp['smtp_from_email'], $this->smtp['smtp_from_name']);
     } else {
         $mail->SetFrom($this->smtp['smtp_server'], $this->smtp['smtp_usr']);
     }
     if (is_array($this->to)) {
         foreach ($this->to as $key => $val) {
             $name = is_numeric($key) ? "" : $key;
             $mail->AddAddress($val, $name);
         }
     } else {
         $mail->AddAddress($this->to, $this->to_name);
     }
     if (!empty($this->smtp['smtp_reply_email'])) {
         $mail->AddReplyTo($this->smtp['smtp_reply_email'], $this->smtp['smtp_reply_name']);
     }
     if ($this->cc) {
         if (is_array($this->cc)) {
             foreach ($this->cc as $keyc => $valcc) {
                 $name = is_numeric($keyc) ? "" : $keyc;
                 $mail->AddCC($valcc, $name);
             }
         } else {
             $mail->AddCC($this->cc, $this->cc_name);
         }
     }
     if ($this->attach) {
         if (is_array($this->attach)) {
             foreach ($this->attach as $key => $val) {
                 $mail->AddAttachment($val);
             }
         } else {
             $mail->AddAttachment($this->attach);
         }
     }
     // 		$mail->SMTPSecure = 'ssl';
     $mail->SMTPSecure = "tls";
     $mail->WordWrap = 50;
     $mail->IsHTML($this->is_html);
     $mail->Subject = $this->subject;
     $mail->Body = $this->body;
     $mail->AltBody = "";
     // return $mail->Body;
     return $mail->Send();
 }
示例#4
0
 /**
  * @brief Function setIndex
  *      envia o email do usuario na index do site
  * @param void
  * @return mensagem indicador de erro ou sucesso
  */
 public function setIndex()
 {
     if (@$_POST) {
         $this->name = Dbcommand::post('name');
         $this->mail_job = Dbcommand::post('mail');
         $this->phone = Dbcommand::post('phone');
         $this->title = Dbcommand::post('title');
         $this->message = Dbcommand::post('message');
         if (empty($this->name) || empty($this->mail_job) || empty($this->message) || empty($this->title)) {
             echo "<script> window.alert('Campo vazio!!') </script>\n\t              <script> window.location = 'index.php'; </script>";
             die;
         }
         if (!ValidationData::name($this->name) || !ValidationData::mail($this->mail_job) || !ValidationData::text($this->message) || !ValidationData::text($this->title)) {
             echo "<script> window.alert('Campo em formato inv&aacute;lido!!') </script>\n                \t<script> window.location = 'index.php'; </script>";
             die;
         } else {
             $mail = new PHPMailer();
             // Classe para enviar emails
             $mail->IsSMTP();
             // Define que  a mensagem sera SMTP
             // Define o remetente
             $mail->From = $this->from;
             // Seu e-mail
             $mail->Sender = $this->from;
             // Seu e-mail
             $mail->FromName = $this->fromName;
             // Seu nome
             // Define os destinatario(s)
             $mail->AddAddress($this->from, $this->name);
             // Sera pra propria
             $mail->AddCC($this->mail_job, "C&oacute;pia | " . $this->fromName);
             // Copia pro Usuario
             $mail->IsHTML(true);
             // Define que o e-mail sera enviado como HTML
             $mail->CharSet = 'utf-8';
             // Charset da mensagem
             // Define a mensagem (Texto e Assunto)
             $mail->Subject = $this->title;
             $mail->Body = $this->message;
             $mail->AltBody = trim(strip_tags($this->message));
             // A mesma mensagem em texto puro
             $sended = $mail->Send();
             // Envia o e-mail
             $mail->ClearAllRecipients();
             // Limpa os destinatarios e os anexos
             $this->name = Criptography::BASE64($this->name, 1);
             $this->mail_job = Criptography::BASE64($this->mail_job, 1);
             $this->phone = Criptography::BASE64($this->phone, 1);
             $this->title = Criptography::BASE64($this->title, 1);
             $this->message = Criptography::BASE64($this->message, 1);
             $this->date_in = Criptography::BASE64(date("Y-m-d H:i:s"), 1);
             Dbcommand::insert('tb_emails', array('EM_NOME', 'EM_EMAIL', 'EM_ASSUNTO', 'EM_MENSAGEM', 'EM_DATA', 'EM_TEL', 'EM_STATUS'), array($this->name, $this->mail_job, $this->title, $this->message, $this->date_in, $this->phone, $this->status));
             if ($sended) {
                 echo "<script> window.alert('Mensagem enviada com Sucesso') </script>\n                    \t <script> window.location = 'index.php'; </script>";
             } else {
                 echo "<script> window.alert('Nao foi poss&iacute;vel enviar o e-mail,\n                            mas ele podera ser visto pelo Administrador do Site.') </script>\n                            <script> window.location = 'index.php'; </script>";
             }
         }
     }
 }
示例#5
0
 /**
  *
  * Can be used to add various types of address
  *
  * @param string $type
  * @param $address
  * @param string $name
  * @throws \InvalidArgumentException
  * @return $this
  * @author Tim Perry
  */
 public function addAddress($type, $address, $name = '')
 {
     if (empty($address) || filter_var($address, FILTER_VALIDATE_EMAIL) === false) {
         $message = "Invalid address please provide a valid email address";
         throw new \InvalidArgumentException($message);
     }
     switch ($type) {
         default:
         case 'to':
             $this->mailer->AddAddress($address, $name);
             break;
         case 'from':
             $this->mailer->SetFrom($address, $name);
             break;
         case 'bcc':
             $this->mailer->AddBCC($address, $name);
             break;
         case 'cc':
             $this->mailer->AddCC($address, $name);
             break;
         case 'replyto':
             $this->mailer->AddReplyTo($address, $name);
             break;
     }
     return $this;
 }
示例#6
0
 /**
  * send an email
  *
  * @param string $toaddress
  * @param string $toname
  * @param string $subject
  * @param string $mailtext
  * @param string $fromaddress
  * @param string $fromname
  * @param bool $html
  */
 public static function send($toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '')
 {
     $SMTPMODE = OC_Config::getValue('mail_smtpmode', 'sendmail');
     $SMTPHOST = OC_Config::getValue('mail_smtphost', '127.0.0.1');
     $SMTPAUTH = OC_Config::getValue('mail_smtpauth', false);
     $SMTPUSERNAME = OC_Config::getValue('mail_smtpname', '');
     $SMTPPASSWORD = OC_Config::getValue('mail_smtppassword', '');
     $mailo = new PHPMailer(true);
     if ($SMTPMODE == 'sendmail') {
         $mailo->IsSendmail();
     } elseif ($SMTPMODE == 'smtp') {
         $mailo->IsSMTP();
     } elseif ($SMTPMODE == 'qmail') {
         $mailo->IsQmail();
     } else {
         $mailo->IsMail();
     }
     $mailo->Host = $SMTPHOST;
     $mailo->SMTPAuth = $SMTPAUTH;
     $mailo->Username = $SMTPUSERNAME;
     $mailo->Password = $SMTPPASSWORD;
     $mailo->From = $fromaddress;
     $mailo->FromName = $fromname;
     $mailo->Sender = $fromaddress;
     $a = explode(' ', $toaddress);
     try {
         foreach ($a as $ad) {
             $mailo->AddAddress($ad, $toname);
         }
         if ($ccaddress != '') {
             $mailo->AddCC($ccaddress, $ccname);
         }
         if ($bcc != '') {
             $mailo->AddBCC($bcc);
         }
         $mailo->AddReplyTo($fromaddress, $fromname);
         $mailo->WordWrap = 50;
         if ($html == 1) {
             $mailo->IsHTML(true);
         } else {
             $mailo->IsHTML(false);
         }
         $mailo->Subject = $subject;
         if ($altbody == '') {
             $mailo->Body = $mailtext . OC_MAIL::getfooter();
             $mailo->AltBody = '';
         } else {
             $mailo->Body = $mailtext;
             $mailo->AltBody = $altbody;
         }
         $mailo->CharSet = 'UTF-8';
         $mailo->Send();
         unset($mailo);
         OC_Log::write('mail', 'Mail from ' . $fromname . ' (' . $fromaddress . ')' . ' to: ' . $toname . '(' . $toaddress . ')' . ' subject: ' . $subject, OC_Log::DEBUG);
     } catch (Exception $exception) {
         OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
         throw $exception;
     }
 }
示例#7
0
function phpmail_send($from, $to, $subject, $message, $attachment_path = NULL, $cc = NULL, $bcc = NULL)
{
    require_once APPPATH . 'modules_core/mailer/helpers/phpmailer/class.phpmailer.php';
    $CI =& get_instance();
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->IsHtml();
    if ($CI->mdl_mcb_data->setting('email_protocol') == 'smtp') {
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        if ($CI->mdl_mcb_data->setting('smtp_security')) {
            $mail->SMTPSecure = $CI->mdl_mcb_data->setting('smtp_security');
        }
        $mail->Host = $CI->mdl_mcb_data->setting('smtp_host');
        $mail->Port = $CI->mdl_mcb_data->setting('smtp_port');
        $mail->Username = $CI->mdl_mcb_data->setting('smtp_user');
        $mail->Password = $CI->mdl_mcb_data->setting('smtp_pass');
    } elseif ($CI->mdl_mcb_data->setting('email_protocol') == 'sendmail') {
        $mail->IsSendmail();
    }
    if (is_array($from)) {
        $mail->SetFrom($from[0], $from[1]);
    } else {
        $mail->SetFrom($from);
    }
    $mail->Subject = $subject;
    $mail->Body = $message;
    $to = strpos($to, ',') ? explode(',', $to) : explode(';', $to);
    foreach ($to as $address) {
        $mail->AddAddress($address);
    }
    if ($cc) {
        $cc = strpos($cc, ',') ? explode(',', $cc) : explode(';', $cc);
        foreach ($cc as $address) {
            $mail->AddCC($address);
        }
    }
    if ($bcc) {
        $bcc = strpos($bcc, ',') ? explode(',', $bcc) : explode(';', $bcc);
        foreach ($bcc as $address) {
            $mail->AddBCC($address);
        }
    }
    if ($attachment_path) {
        $mail->AddAttachment($attachment_path);
    }
    if ($mail->Send()) {
        if (isset($CI->load->_ci_classes['session'])) {
            $CI->session->set_flashdata('custom_success', $CI->lang->line('email_success'));
            return TRUE;
        }
    } else {
        if (isset($CI->this->load->_ci_classes['session'])) {
            $CI->session->set_flashdata('custom_error', $mail->ErrorInfo);
            return FALSE;
        }
    }
}
示例#8
0
function sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message, $type = "plain", $cc = "", $bcc = "")
{
    global $settings, $locale;
    require_once INCLUDES . "class.phpmailer.php";
    $mail = new PHPMailer();
    if (file_exists(INCLUDES . "language/phpmailer.lang-" . $locale['phpmailer'] . ".php")) {
        $mail->SetLanguage($locale['phpmailer'], INCLUDES . "language/");
    } else {
        $mail->SetLanguage("en", INCLUDES . "language/");
    }
    if (!$settings['smtp_host']) {
        $mail->IsMAIL();
    } else {
        $mail->IsSMTP();
        $mail->Host = $settings['smtp_host'];
        $mail->Port = $settings['smtp_port'];
        $mail->SMTPAuth = $settings['smtp_auth'] ? true : false;
        $mail->Username = $settings['smtp_username'];
        $mail->Password = $settings['smtp_password'];
    }
    $mail->CharSet = $locale['charset'];
    $mail->From = $fromemail;
    $mail->FromName = $fromname;
    $mail->AddAddress($toemail, $toname);
    $mail->AddReplyTo($fromemail, $fromname);
    if ($cc) {
        $cc = explode(", ", $cc);
        foreach ($cc as $ccaddress) {
            $mail->AddCC($ccaddress);
        }
    }
    if ($bcc) {
        $bcc = explode(", ", $bcc);
        foreach ($bcc as $bccaddress) {
            $mail->AddBCC($bccaddress);
        }
    }
    if ($type == "plain") {
        $mail->IsHTML(false);
    } else {
        $mail->IsHTML(true);
    }
    $mail->Subject = $subject;
    $mail->Body = $message;
    if (!$mail->Send()) {
        $mail->ErrorInfo;
        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        return false;
    } else {
        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        return true;
    }
}
示例#9
0
 public function Send(IEmailMessage $emailMessage)
 {
     $this->phpMailer->ClearAllRecipients();
     $this->phpMailer->ClearReplyTos();
     $this->phpMailer->CharSet = $emailMessage->Charset();
     $this->phpMailer->Subject = $emailMessage->Subject();
     $this->phpMailer->Body = $emailMessage->Body();
     $from = $emailMessage->From();
     $defaultFrom = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_ADDRESS);
     $defaultName = Configuration::Instance()->GetSectionKey(ConfigSection::EMAIL, ConfigKeys::DEFAULT_FROM_NAME);
     $address = empty($defaultFrom) ? $from->Address() : $defaultFrom;
     $name = empty($defaultName) ? $from->Name() : $defaultName;
     $this->phpMailer->SetFrom($address, $name);
     $replyTo = $emailMessage->ReplyTo();
     $this->phpMailer->AddReplyTo($replyTo->Address(), $replyTo->Name());
     $to = $this->ensureArray($emailMessage->To());
     $toAddresses = new StringBuilder();
     foreach ($to as $address) {
         $toAddresses->Append($address->Address());
         $this->phpMailer->AddAddress($address->Address(), $address->Name());
     }
     $cc = $this->ensureArray($emailMessage->CC());
     foreach ($cc as $address) {
         $this->phpMailer->AddCC($address->Address(), $address->Name());
     }
     $bcc = $this->ensureArray($emailMessage->BCC());
     foreach ($bcc as $address) {
         $this->phpMailer->AddBCC($address->Address(), $address->Name());
     }
     if ($emailMessage->HasStringAttachment()) {
         Log::Debug('Adding email attachment %s', $emailMessage->AttachmentFileName());
         $this->phpMailer->AddStringAttachment($emailMessage->AttachmentContents(), $emailMessage->AttachmentFileName());
     }
     Log::Debug('Sending %s email to: %s from: %s', get_class($emailMessage), $toAddresses->ToString(), $from->Address());
     $success = false;
     try {
         $success = $this->phpMailer->Send();
     } catch (Exception $ex) {
         Log::Error('Failed sending email. Exception: %s', $ex);
     }
     Log::Debug('Email send success: %d. %s', $success, $this->phpMailer->ErrorInfo);
 }
示例#10
0
 public function init()
 {
     if ($this->finish()) {
         $mail = $this->phpmailer();
         $mail = new PHPMailer(true);
         $mail->IsHTML(true);
         try {
             $mail->Body = $this->body();
             $mail->Subject = $this->subject();
             $mail->From = $this->from('email');
             $mail->FromName = $this->from('name');
             $mail->AddReplyTo($this->from('email'));
             /** SMTP OPTIONS **/
             if ($this->Config->smtp['use'] != 'no') {
                 $mail->IsSMTP();
                 $mail->Host = $this->Config->smtp['host'];
                 $mail->Port = $this->Config->smtp['port'];
                 $mail->SMTPSecure = $this->Config->smtp['secure'];
                 if ($this->Config->smtp['auth'] != 'no') {
                     $mail->SMTPAuth = true;
                     $mail->Username = $this->Config->smtp['username'];
                     $mail->Password = $this->Config->smtp['password'];
                 }
             }
             // Adds Addresses
             foreach ($this->Config->Address as $Address) {
                 if (!empty($Address)) {
                     $mail->AddAddress($Address);
                 }
             }
             // Adds cc
             foreach ($this->Config->Cc as $Address) {
                 if (!empty($Address)) {
                     $mail->AddCC($Address);
                 }
             }
             $mail->CharSet = $this->Config->charset;
             $email = $mail->Send();
             if ($email) {
                 if (IS_AJAX) {
                     echo json_encode(true);
                 } else {
                     echo $this->msg['success'];
                 }
             }
         } catch (Exception $e) {
             if (IS_AJAX) {
                 echo json_encode(false);
             } else {
                 echo $this->msg['error'];
             }
         }
     }
 }
示例#11
0
 /**
  * 发送邮件
  *
  * @param string $to
  * @param string $to_name
  * @param string $subject
  * @param string $body
  * @param string $mailtype
  * @return boolean
  */
 public static function send($to, $to_name, $subject, $body, $chaosong = array(), $mailtype = 'txt')
 {
     self::init();
     $send_type = mod_config::get_one_config('fl_sendemailtype') == '1' ? 'smtp' : 'mail';
     $mail = new PHPMailer();
     $mail->SMTPDebug = false;
     // 发送方式
     if ($send_type == 'smtp') {
         self::smtp_init();
         $mail->IsSMTP();
         $mail->Host = self::$smtp_server;
         $mail->Port = self::$smtp_port;
         $mail->SmtpSsl = self::$smtp_ssl;
         // SSL 连接
         if (self::$smtp_auth) {
             $mail->SMTPAuth = true;
             $mail->Username = self::$smtp_user;
             $mail->Password = self::$smtp_pwd;
         } else {
             $mail->SMTPAuth = false;
         }
     } elseif ($send_type == 'mail') {
         $mail->IsMail();
     }
     // 发件人邮箱
     $mail->From = self::$from_email;
     // 发件人名称
     if (self::$from_name != '') {
         $mail->FromName = self::$from_name;
     }
     // 收件人邮箱和姓名
     $mail->AddAddress($to, $to_name);
     if ($chaosong) {
         foreach ($chaosong as $v) {
             $mail->AddCC($v['to'], $v['name']);
         }
     }
     // 邮件编码
     $mail->CharSet = self::$charset;
     // 邮件编码方式
     $mail->Encoding = "base64";
     // 邮件格式类型
     if ($mailtype == 'txt') {
         $mail->IsHTML(false);
     } elseif ($mailtype == 'html') {
         $mail->IsHTML(true);
         $mail->AltBody = "text/html";
     }
     $mail->Subject = $subject;
     // 邮件主题
     $mail->Body = $body;
     // 邮件内容D
     return !$mail->Send() ? false : true;
 }
 private function convert_mail()
 {
     foreach ($this->mail_to_send->get_recipients() as $recipient => $name) {
         $this->mailer->AddAddress($recipient, $name);
     }
     // cc
     foreach ($this->mail_to_send->get_cc_recipients() as $recipient => $name) {
         $this->mailer->AddCC($recipient, $name);
     }
     // bcc
     foreach ($this->mail_to_send->get_bcc_recipients() as $recipient => $name) {
         $this->mailer->AddBCC($recipient, $name);
     }
     // from
     $this->mailer->SetFrom($this->mail_to_send->get_sender_mail(), $this->mail_to_send->get_sender_name());
     $this->mailer->AddReplyTo($this->mail_to_send->get_reply_to_mail() ? $this->mail_to_send->get_reply_to_mail() : $this->mail_to_send->get_sender_mail(), $this->mail_to_send->get_reply_to_name() ? $this->mail_to_send->get_reply_to_name() : $this->mail_to_send->get_sender_name());
     $this->mailer->Subject = $this->mail_to_send->get_subject();
     // content
     $this->convert_content();
 }
示例#13
0
 public function send($retry = 3)
 {
     $this->ci =& get_instance();
     $configFile = 'email';
     $this->ci->config->load($configFile, true);
     $mail = new PHPMailer(true);
     $mail->IsSMTP();
     // set mailer to use SMTP
     $mail->Host = $this->ci->config->item('smtp_host', $configFile);
     $mail->Port = $this->ci->config->item('smtp_port', $configFile);
     $mail->Username = $this->ci->config->item('smtp_user', $configFile);
     $mail->Password = $this->ci->config->item('smtp_passwd', $configFile);
     $mail->From = $this->ci->config->item('from', $configFile);
     $mail->SMTPAuth = true;
     $mail->CharSet = "utf-8";
     if (!empty($this->_fromName)) {
         $mail->FromName = $this->_fromName;
     } else {
         $mail->FromName = $this->ci->config->item('from_name', $configFile);
     }
     foreach ($this->_rcvAddrs as $rcver) {
         $mail->AddAddress($rcver);
     }
     foreach ($this->_ccAddrs as $ccAddr) {
         $mail->AddCC($ccAddr);
     }
     $mail->IsHTML(true);
     // set email format to HTML
     $mail->Subject = $this->_title;
     if ($this->_bodyType == 'plain') {
         $mail->Body = nl2br($this->_body);
     } else {
         if ($this->_bodyType == 'html') {
             $mail->Body = $this->_body;
         } else {
             $mail->Body = $this->_body;
         }
     }
     foreach ($this->_attachs as $attachFile) {
         $mail->AddAttachment($attachFile, basename($attachFile));
     }
     while ($retry) {
         try {
             $mail->Send();
             return true;
         } catch (Exception $e) {
             $retry--;
         }
     }
     $logParams = array('message' => $e->getMessage(), 'receiver' => $this->_rcvAddrs, 'cc' => $this->_ccAddrs, 'title' => $this->_title, 'body' => $this->_body);
     $ci =& get_instance();
     $ci->log->log('warning', 'mail failed', $logParams);
     return false;
 }
 /**
  * Adds all of the addresses
  * @access public
  * @param string $sAddress
  * @param string $sName
  * @param string $sType
  * @return boolean
  */
 function SetAddress($sAddress, $sName = '', $sType = 'to')
 {
     switch ($sType) {
         case 'to':
             return $this->Mail->AddAddress($sAddress, $sName);
         case 'cc':
             return $this->Mail->AddCC($sAddress, $sName);
         case "bcc":
             return $this->Mail->AddBCC($sAddress, $sName);
     }
     return false;
 }
 function send()
 {
     $mail = new PHPMailer();
     $mail->SMTPDebug = $this->SMTPDebug;
     $mail->IsSMTP();
     // set mailer to use SMTP
     $mail->SMTPAuth = $this->SMTPAuth;
     //設定SMTP需要驗證
     $mail->SMTPSecure = $this->SMTPSecure;
     // Gmail的SMTP主機需要使用SSL連線
     $mail->Host = $this->Host;
     //Gamil的SMTP主機
     $mail->Port = $this->Port;
     //Gamil的SMTP主機的SMTP埠位為465埠。
     $mail->CharSet = $this->CharSet;
     //設定郵件編碼
     $mail->Username = $this->UserName;
     $mail->Password = $this->Password;
     $mail->From = $this->from;
     $mail->FromName = $this->fromName;
     foreach ($this->to as $to_address) {
         $mail->AddAddress($to_address['email'], $to_address['name']);
     }
     foreach ($this->cc as $to_address) {
         $mail->AddCC($to_address['email'], $to_address['name']);
     }
     foreach ($this->bcc as $to_address) {
         $mail->AddBCC($to_address['email'], $to_address['name']);
     }
     $mail->AddReplyTo($this->from, $this->fromName);
     $mail->WordWrap = 50;
     // set word wrap to 50 characters
     if (!empty($this->attachments)) {
         foreach ($this->attachments as $attachment) {
             if (empty($attachment['asfile'])) {
                 $mail->AddAttachment($attachment['filename']);
             } else {
                 $mail->AddAttachment($attachment['filename'], $attachment['asfile']);
             }
         }
     }
     $mail->IsHTML(true);
     // set email format to HTML
     $mail->Subject = $this->subject;
     $mail->Body = $this->html_body;
     //設定郵件內容
     $result = $mail->Send();
     if ($result === false) {
         $result = $mail->ErrorInfo;
     }
     return $result;
 }
示例#16
0
 public function addAddressToMailer($type, $addr)
 {
     if (empty($addr)) {
         return;
     }
     $a = array_filter(array_map('trim', explode(',', $addr)));
     foreach ($a as $address) {
         switch ($type) {
             case 'to':
                 $this->mail->AddAddress($address);
                 break;
             case 'cc':
                 $this->mail->AddCC($address);
                 break;
             case 'bcc':
                 $this->mail->AddBCC($address);
                 break;
             case 'replyTo':
                 $this->mail->AddReplyTo($address);
         }
     }
 }
示例#17
0
function sendMail($toMail, $toName, $subject, $textContent, $fromMail, $fromName, $html = 1, $mailcc = '')
{
    //require_once "class.phpmailer.php";
    //require_once "class.smtp.php";
    require_once "class.phpmailer.php";
    require_once "class.smtp.php";
    $sendMail = $toMail;
    $sendName = $toName;
    $mailSubject = $subject;
    $mail = new PHPMailer();
    $mail->Subject = $mailSubject;
    $mail->From = $fromMail;
    $mail->FromName = $fromName;
    $mail->Body = $textContent;
    if ($mailcc != '') {
        $mail->AddCC($mailcc);
    }
    if ($html == 1) {
        $mail->isHTML(true);
    }
    if (preg_match("/,/i", $sendMail)) {
        $arr = explode(",", $sendMail);
    } else {
        $arr[0] = $sendMail;
    }
    foreach ($arr as $val) {
        if (preg_match("/@/i", $val)) {
            $name = $val;
            $mail->AddAddress($val, $sendName);
            //$mail->AddBCC("*****@*****.**", "Debopam");
            $mail->AddReplyTo($fromMail, $fromName);
            if (!$mail->Send()) {
                $flag = 0;
                echo "Message was not sent <p>";
                echo "Mailer Error: " . $mail->ErrorInfo;
                exit;
            } else {
                $flag = 1;
            }
            $mail->ClearAllRecipients();
        }
    }
    if ($flag == 1) {
        return true;
    } else {
        return false;
    }
}
示例#18
0
function sendMail($body, $subject, $recipient, $recipientName)
{
    global $mailHost, $mailPort, $mailUsername, $mailPassword, $mailSetFrom, $mailAddReplyTo;
    //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
    $mail = new PHPMailer();
    //$body             = file_get_contents('contents.html');
    //$body             = eregi_replace("[\]",'',$body);
    //$body = "Esto es un mail de prueba";
    $mail->IsSMTP();
    // telling the class to use SMTP
    $mail->Host = "smtp.ismsolar.com";
    // SMTP server
    $mail->SMTPDebug = 1;
    // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth = true;
    // enable SMTP authentication
    $mail->Host = $mailHost;
    //"smtp.ismsolar.com"; // sets the SMTP server
    $mail->Port = $mailPort;
    //587;                    // set the SMTP port for the GMAIL server
    $mail->Username = $mailUsername;
    //"uea984c"; // SMTP account username
    $mail->Password = $mailPassword;
    //"Amljp77s";        // SMTP account password
    $mail->SetFrom($mailSetFrom, "Soporte");
    //('*****@*****.**', 'First Last');
    $mail->AddReplyTo($mailAddReplyTo, "Soporte");
    //("*****@*****.**","First Last");
    $mail->Subject = $subject;
    $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
    // optional, comment out and test
    $mail->MsgHTML($body);
    $address = $recipient;
    //"*****@*****.**";
    $mail->AddAddress($address, $recipientName);
    $mail->AddCC('*****@*****.**', 'SOPORTE ISM');
    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
    if (!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
        return false;
    } else {
        echo "Message sent!";
        return true;
    }
}
示例#19
0
 function send_basic_text_email($email_tos, $email_ccs, $email_subject, $email_message)
 {
     //following code adapted from phpMailer 2.2.1 README
     $mail = new PHPMailer();
     if (AppSettings::gv("smtp_server") == "localhost") {
         $mail->IsSendmail();
     } else {
         $mail->IsSMTP();
         // set mailer to use SMTP
         $mail->Host = AppSettings::gv("smtp_server");
         // specify main and backup server
         $mail->SMTPAuth = true;
         // turn on SMTP authentication
         $mail->Username = AppSettings::gv("smtp_user");
         // SMTP username
         $mail->Password = AppSettings::gv("smtp_pass");
         // SMTP password
     }
     $mail->From = AppSettings::gv("std_email_from");
     $mail->FromName = "New England Trade";
     foreach ($email_tos as $email_to) {
         //$mail->AddAddress("*****@*****.**", "Josh Adams");
         //$mail->AddAddress("*****@*****.**");                  // name is optional
         $mail->AddAddress($email_to);
         //echo "yo:".$email_to;
     }
     foreach ($email_ccs as $email_cc) {
         $mail->AddCC($email_cc);
     }
     //$mail->AddReplyTo("*****@*****.**", "Information");
     $mail->WordWrap = 50;
     // set word wrap to 50 characters
     //$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
     //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
     //$mail->IsHTML(true);                                  // set email format to HTML
     $mail->Subject = $email_subject;
     $mail->Body = $email_message;
     //$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
     if (!$mail->Send()) {
         echo "Message could not be sent. <p>";
         echo "Mailer Error: " . $mail->ErrorInfo . " ++";
         echo "<p>Developer note: Maybe the email address is invalid? Please try changing the user email address. <a href='/index.php'>Go back</a> to site.";
         exit;
     }
     return true;
     //echo "Message has been sent";
 }
示例#20
0
 public function send()
 {
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->SMTPDebug = 0;
     $mail->Host = 'smtp.gmail.com';
     $mail->SMTPAuth = true;
     $mail->Username = $this->data['correoEmisor'];
     $mail->Password = $this->data['contrasena'];
     $mail->SMTPSecure = 'ssl';
     $mail->Port = 465;
     $mail->From = $this->data['correoEmisorEm'];
     $mail->FromName = $this->data['nombreEmisor'];
     foreach ($this->data['correoDestino'] as $correoDestino) {
         $mail->AddAddress(trim($correoDestino), $this->data['nombreDestino']);
     }
     $mail->AddReplyTo($this->data['correoEmisorEm'], $this->data['nombreEmisor']);
     $mail->AddCC($this->data['cc']);
     $mail->IsHTML(true);
     $mail->Subject = $this->data['asunto'];
     $mail->MsgHTML($this->data['body']);
     $mail->AltBody = $this->data['altBody'];
     // Si se enviaran archivos en el mail los adjunta.
     if (isset($this->data['adjuntos'])) {
         if (count($this->data['adjuntos'] > 0)) {
             // Si quiere que los archivos se manden en un zip.
             if ($this->zip) {
                 $pathZip = $this->makeZip();
                 $mail->AddAttachment($pathZip, 'Documentos.zip');
             } else {
                 foreach ($this->data['adjuntos'] as $fileName => $pathFile) {
                     $mail->AddAttachment($pathFile, $fileName);
                 }
             }
         }
     }
     $result = array('msg' => 'Mensaje enviado correctamente.');
     if (!$mail->Send()) {
         $result['msg'] = 'El email no se pudo enviar.';
         $result['error'] = $mail->ErrorInfo;
     }
     if ($this->zip) {
         unlink($pathZip);
     }
     return $result;
 }
示例#21
0
function sendmail($to, $replyto, $subject, $message)
{
    //path to PHPMailer class
    require 'phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail->CharSet = "UTF-8";
    // telling the class to use SMTP
    $mail->IsSMTP();
    // enables SMTP debug information (for testing)
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPDebug = 2;
    // enable SMTP authentication
    $mail->SMTPAuth = true;
    // sets the prefix to the servier
    $mail->SMTPSecure = "tls";
    // sets GMAIL as the SMTP server
    $mail->Host = "smtp.netsite.dk";
    // set the SMTP port for the GMAIL server
    $mail->Port = 587;
    // GMAIL username
    $mail->Username = "******";
    // GMAIL password
    $mail->Password = "******";
    //Set reply-to email this is your own email, not the gmail account
    //    $mail->clearReplyTos();
    $mail->addReplyTo($replyto);
    //used for sending emails
    $mail->SetFrom('*****@*****.**', 'Projektstyring');
    // Mail Subject
    $mail->Subject = $subject;
    //Main message
    $mail->isHTML(true);
    $mail->Body = $message;
    //Adding recipients
    foreach ($to as $recipient) {
        $mail->AddCC($recipient, "");
    }
    if (!$mail->send()) {
        echo $mail->ErrorInfo;
        return false;
    } else {
        //successfully sent
        return true;
    }
}
示例#22
0
 public function sendmail($title, $subject, $body, $add_address, $add_cc = '', $add_bcc = '')
 {
     include_once 'libraries/sendmail/class.phpmailer.php';
     $mail = new PHPMailer();
     $mail->IsSMTP();
     // Gọi đến class xử lý SMTP
     $mail->Host = CONS_HOST_SMTP_SERVER;
     // tên SMTP server
     $mail->SMTPDebug = 2;
     // enables SMTP debug information (for testing): 1 = errors and messages, 2 = messages only
     $mail->SMTPAuth = true;
     // Sử dụng đăng nhập vào account
     $mail->Port = 25;
     // Thiết lập cổng gửi email của máy
     $mail->Username = CONS_SEND_MAIL_ACCOUNT;
     // SMTP account username
     $mail->Password = CONS_SEND_MAIL_PASSWORD;
     // SMTP account password
     $mail->IsHTML(true);
     $mail->SetFrom(CONS_SEND_MAIL_ACCOUNT, $title);
     //Thiet lap thong tin nguoi gui va email nguoi gui
     foreach ($add_address as $row) {
         $mail->AddAddress($row['email'], $row['name']);
     }
     //Thiết lập thông tin người nhận
     if ($add_cc != '') {
         foreach ($add_cc as $row) {
             $mail->AddCC($row['email'], $row['name']);
         }
     }
     if ($add_bcc != '') {
         foreach ($add_bcc as $row) {
             $mail->AddBCC($row['email'], $row['name']);
         }
     }
     $mail->CharSet = "utf-8";
     $mail->Subject = $subject;
     //Thiết lập tiêu đề
     $mail->Body = $body;
     //Thiết lập nội dung chính của email
     if ($mail->Send()) {
         return true;
     }
 }
示例#23
0
文件: System.php 项目: hqd276/bigs
 static function send_mail($to, $subject, $content, $from = 'Cpvm.vn', $cc = '', $attachment = array())
 {
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->SetLanguage("vn", ROOT_PATH . 'includes/enbac/Mailer/language/');
     $mail->Host = SMTP_HOST;
     $mail->Port = SMTP_PORT;
     $mail->SMTPAuth = SMTP_AUTH;
     //$mail->SMTPSecure = "tls"; // sets the prefix to the servier
     //$mail->Password = SMTP_PASS; // SMTP password
     $mail->From = SMTP_FROM_EMAIL;
     // Email duoc gui tu???
     $mail->Username = SMTP_FROM_EMAIL;
     // SMTP username
     $mail->FromName = $from;
     // Ten hom email duoc gui
     $mail->AddAddress($to, "");
     // Dia chi email va ten nhan
     if ($cc) {
         $mail->AddCC($cc, "");
         // Dia chi email va ten nhan
     }
     $mail->IsHTML(true);
     // Gui theo dang HTML
     $mail->Subject = $subject;
     // Chu de email
     $mail->Body = $content;
     // Noi dung html
     if (count($attachment) > 0) {
         foreach ($attachment as $at) {
             $mail->AddAttachment($at['file_path'], $at['fileatname'], $at['encoding'], $at['type']);
         }
     }
     if (!$mail->Send()) {
         echo $mail->ErrorInfo;
         return false;
     } else {
         return true;
     }
 }
示例#24
0
文件: Mail.php 项目: hkhateb/linet3
 public function send()
 {
     Yii::import('application.extensions.smtpmail.PHPMailer');
     $mail = new PHPMailer();
     $mail->IsSMTP();
     $mail->Host = Yii::app()->user->getSetting('company.mail.server');
     $mail->SMTPAuth = Yii::app()->user->getSetting('company.mail.user') != '' ? true : false;
     $mail->SMTPSecure = Yii::app()->user->getSetting('company.mail.ssl') ? 'tls' : '';
     $mail->CharSet = 'utf-8';
     $mail->Port = Yii::app()->user->getSetting('company.mail.port');
     $mail->Username = Yii::app()->user->getSetting('company.mail.user');
     $mail->Password = Yii::app()->user->getSetting('company.mail.password');
     //$mail->SetFrom($this->from);
     //echo $this->files;
     if ($this->files != '') {
         $file = Files::model()->findByPk($this->files);
         if ($file != null) {
             //echo $file->getFullPath().";;".$file->name;
             $mail->AddAttachment($file->getFullFilePath(), $file->name);
         }
     }
     $mail->SetFrom(Yii::app()->user->settings['company.mail.address']);
     $mail->AddCC($this->cc);
     //.$this->cc
     $mail->AddBcc($this->bcc);
     $mail->Subject = $this->subject;
     $mail->MsgHTML($this->body);
     $mail->AddAddress($this->to, "");
     if (!$mail->Send()) {
         //echo "Mailer Error: " . $mail->ErrorInfo;
         throw new CHttpException(501, Yii::t('app', "Mailer Error: ") . $mail->ErrorInfo . $mail->Username);
     } else {
         $this->sent++;
         $this->save();
         Yii::app()->user->setFlash('success', Yii::t('app', 'Message sent!'));
         //echo "Message sent!";
     }
     //*/
     //Yii::app()->end();
 }
示例#25
0
 public function sendMail($config, $SetFrom, $addAddress, $AddCC, $subject, $message, $addStringAttachment)
 {
     $mail = new PHPMailer(true);
     $mail->IsSMTP();
     try {
         $mail->Timeout = 3600;
         $mail->SMTPDebug = 0;
         $mail->Debugoutput = 'html';
         $mail->SMTPSecure = 'ssl';
         $mail->Host = $config['host'];
         $mail->SMTPAuth = true;
         $mail->Host = $config['host'];
         $mail->Port = $config['port'];
         $mail->Username = $config['user'];
         $mail->Password = $config['pass'];
         $mail->SetFrom($SetFrom['email'], $SetFrom['name']);
         foreach ($addAddress as $reply) {
             $mail->AddAddress($reply['email'], $reply['name']);
         }
         foreach ($AddCC as $cc) {
             $mail->AddCC($cc['email'], $cc['name']);
         }
         foreach ($addStringAttachment as $cc) {
             $mail->addStringAttachment($addStringAttachment['base64'], $addStringAttachment['name'], 'base64', 'application/' . $addStringAttachment['ext']);
         }
         $mail->Subject = $subject;
         $mail->AltBody = 'To view the message, please use an HTML compatible email viewer !';
         $mail->MsgHTML($this->config->email->header . $message . $this->config->email->header);
         $mail->Send();
         return true;
     } catch (phpmailerException $e) {
         echo $e->errorMessage();
         //Pretty error messages from PHPMailer
         return false;
     } catch (Exception $e) {
         echo $e->getMessage();
         //Boring error messages from anything else!
         return false;
     }
 }
示例#26
0
function mailer($fname, $fmail, $to, $subject, $content, $type = 0, $file = "", $cc = "", $bcc = "")
{
    global $config;
    global $g5;
    // 메일발송 사용을 하지 않는다면
    if (!$config['cf_email_use']) {
        return;
    }
    if ($type != 1) {
        $content = nl2br($content);
    }
    $mail = new PHPMailer();
    // defaults to using php "mail()"
    if (defined('G5_SMTP') && G5_SMTP) {
        $mail->IsSMTP();
        // telling the class to use SMTP
        $mail->Host = G5_SMTP;
        // SMTP server
    }
    $mail->From = $fmail;
    $mail->FromName = $fname;
    $mail->Subject = $subject;
    $mail->AltBody = "";
    // optional, comment out and test
    $mail->MsgHTML($content);
    $mail->AddAddress($to);
    if ($cc) {
        $mail->AddCC($cc);
    }
    if ($bcc) {
        $mail->AddBCC($bcc);
    }
    //print_r2($file); exit;
    if ($file != "") {
        foreach ($file as $f) {
            $mail->AddAttachment($f['path'], $f['name']);
        }
    }
    return $mail->Send();
}
 public function enviar_correo($data)
 {
     $exito = null;
     $mail = new PHPMailer();
     $mail->SMTPDebug = false;
     $mail->CharSet = "UTF-8";
     $mail->IsSMTP();
     $mail->IsHTML(true);
     $mail->SMTPAuth = true;
     // enable SMTP authentication
     $mail->Timeout = 60;
     //ZIMBRA
     $mail->Host = "10.250.100.9";
     $mail->Port = 465;
     $mail->SMTPSecure = "ssl";
     $mail->Mailer = "smtp";
     //GMAIL
     //$mail->SMTPSecure = "tls";
     //$mail->Host = "smtp.gmail.com";
     //$mail->Port = 465;
     $mail->Username = "******";
     $mail->Password = "******";
     //DATOS DEL CORREO
     $mail->From = "*****@*****.**";
     $mail->FromName = "Tablero de Control Jefatura de Gobierno";
     foreach ($data['to'] as $value) {
         $mail->AddAddress($value);
     }
     if (isset($data['cc'])) {
         foreach ($data['cc'] as $value) {
             $mail->AddCC($value);
         }
     }
     $mail->Subject = $data['asunto'];
     $mail->Body = $data['mensaje'];
     //$mail->AltBody = $data['mensaje'];
     $exito = $mail->Send();
     return $exito;
 }
示例#28
0
	function send($options = array()) {
		$mail = new PHPMailer();
		
		$mail->IsSMTP();
		$mail->Host 		= empty($options['host']) ? SMPP_HOST : $options['host'];
		$mail->SMTPAuth 	= true;
		$mail->Port 		= 25;
		$mail->Username 	= empty($options['user']) ? SMPP_USER : $options['user'];
		$mail->Password 	= empty($options['pass']) ? SMPP_PASS : $options['pass'];
		$mail->From 		= empty($options['from']) ? SMPP_FROM : $options['from'];
		$mail->FromName 	= empty($options['name']) ? SMPP_NAME : $options['name'];
		$mail->Subject 	= $options['subject'];
		$mail->IsHTML(true);
		$mail->AddAddress($options['to']);

		if (isset($options['cc'])) {
			foreach ($options['cc'] as $i => $email) {
				$mail->AddCC($email);	
			}			
		} 
		
		if (isset($options['attach'])) {
			foreach ($options['attach'] as $i => $file) {
				if ($file[1]) {
					$mail->AddAttachment($file[0], $file[1]);		
				} else {
					$mail->AddAttachment($file[0]);		
				}
			}
		}

		$mail->Body = $options['body'];
		if (!$mail->Send()) {
			echo "<pre>[ERROR] Can't send email: ".$options['to']."\n\n Error: ".$mail->ErrorInfo."</pre>";
			return false;
		} else {
			return true;
		}      
	}	
示例#29
0
 public function send()
 {
     // Create a PHP Mailer object and set it up
     $mailer = new \PHPMailer(true);
     $mailer->IsMail();
     // Set the emails subject
     $mailer->Subject = $this->subject;
     // Set the from address
     if (!empty($this->from)) {
         $mailer->SetFrom($this->from['email'], $this->from['name'], true);
     }
     // Set the to address
     foreach ($this->to as $to) {
         $mailer->AddAddress($to['email'], $to['name']);
     }
     // cc
     foreach ($this->cc as $cc) {
         $mailer->AddCC($cc['email'], $cc['name']);
     }
     // bcc
     foreach ($this->bcc as $bcc) {
         $mailer->AddBCC($bcc['email'], $bcc['name']);
     }
     // If we have an HTML body, set that on the message
     // and mark it as an HTML email
     if (!empty($this->htmlBody)) {
         $mailer->Body = $this->htmlBody;
         $mailer->AltBody = $this->textBody;
         $mailer->IsHTML();
     } else {
         $mailer->Body = $this->textBody;
     }
     // Attachments
     foreach ($this->attachments as $attachment) {
         $mailer->AddStringAttachment($attachment['content'], $attachment['filename'], 'base64', $attachment['mime']);
     }
     // Finally, try and send teh message
     return $mailer->Send();
 }
 public function enviar_correo($data)
 {
     $exito = null;
     $mail = new PHPMailer();
     $mail->SMTPDebug = false;
     $mail->CharSet = "UTF-8";
     $mail->IsSMTP();
     $mail->IsHTML(true);
     $mail->SMTPAuth = true;
     // enable SMTP authentication
     $mail->Timeout = 60;
     //ZIMBRA
     $mail->Host = "10.250.102.152";
     $mail->Port = 25;
     $mail->SMTPSecure = "tls";
     $mail->Mailer = "smtp";
     //GMAIL
     //$mail->SMTPSecure = "tls";
     //$mail->Host = "smtp.gmail.com";
     //$mail->Port = 465;
     $mail->Username = "******";
     $mail->Password = "******";
     //DATOS DEL CORREO
     $mail->From = "*****@*****.**";
     $mail->FromName = "Sistema de acuerdos de la CGDF";
     foreach ($data['to'] as $value) {
         $mail->AddAddress($value);
     }
     if (isset($data['cc'])) {
         foreach ($data['cc'] as $value) {
             $mail->AddCC($value);
         }
     }
     $mail->Subject = $data['asunto'];
     $mail->Body = $data['mensaje'];
     //$mail->AltBody = $data['mensaje'];
     $exito = $mail->Send();
     return $exito;
 }