コード例 #1
0
ファイル: mailer.php プロジェクト: sivamkrish/acceleration
function sendgmail($addr, $body)
{
    $config = parse_ini_file('../../catchit/email_config.ini');
    require_once "phpmailer/class.phpmailer.php";
    include "phpmailer/class.smtp.php";
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "tls";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587;
    $mail->Username = $config['address'];
    $mail->Password = $config['password'];
    $mail->Priority = 3;
    $mail->CharSet = 'UTF-8';
    $mail->Encoding = '8bit';
    $mail->Subject = 'Data from Catchit';
    $mail->ContentType = 'text/html; charset=utf-8\\r\\n';
    $mail->From = $config['address'];
    $mail->FromName = 'Catchit';
    $mail->WordWrap = 900;
    $mail->AddAddress($addr);
    $mail->isHTML(FALSE);
    $mail->Body = $body;
    $mail->Send();
    $mail->SmtpClose();
    if ($mail->IsError()) {
        return 'failed to send';
    } else {
        return 'Email has been sent';
    }
}
コード例 #2
0
 /**
  * Short description of method send
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return int
  */
 public function send()
 {
     $returnValue = (int) 0;
     foreach ($this->messages as $message) {
         if ($message instanceof tao_helpers_transfert_Message) {
             $this->mailer->SetFrom($message->getFrom());
             $this->mailer->AddReplyTo($message->getFrom());
             $this->mailer->Subject = $message->getTitle();
             $this->mailer->AltBody = strip_tags(preg_replace("/<br.*>/i", "\n", $message->getBody()));
             $this->mailer->MsgHTML($message->getBody());
             $this->mailer->AddAddress($message->getTo());
             try {
                 if ($this->mailer->Send()) {
                     $message->setStatus(tao_helpers_transfert_Message::STATUS_SENT);
                     $returnValue++;
                 }
                 if ($this->mailer->IsError()) {
                     if (DEBUG_MODE) {
                         echo $this->mailer->ErrorInfo . "<br>";
                     }
                     $message->setStatus(tao_helpers_transfert_Message::STATUS_ERROR);
                 }
             } catch (phpmailerException $pe) {
                 if (DEBUG_MODE) {
                     print $pe;
                 }
             }
         }
         $this->mailer->ClearReplyTos();
         $this->mailer->ClearAllRecipients();
     }
     $this->mailer->SmtpClose();
     return (int) $returnValue;
 }
コード例 #3
0
ファイル: phpmailerTest.php プロジェクト: NurulRizal/BB
 /**
  * Test error handling
  */
 function test_Error()
 {
     $this->Mail->Subject .= ": This should be sent";
     $this->BuildBody();
     $this->Mail->ClearAllRecipients();
     // no addresses should cause an error
     $this->assertTrue($this->Mail->IsError() == false, "Error found");
     $this->assertTrue($this->Mail->Send() == false, "Send succeeded");
     $this->assertTrue($this->Mail->IsError(), "No error found");
     $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
     $this->Mail->AddAddress($_REQUEST['mail_to']);
     $this->assertTrue($this->Mail->Send(), "Send failed");
 }
コード例 #4
0
function SendMail($ToEmail, $subject, $MessageHTML)
{
    require_once 'class.phpmailer.php';
    // Add the path as appropriate
    $Mail = new PHPMailer();
    $Mail->IsSMTP();
    // Use SMTP
    $Mail->Host = "smtp.gmail.com";
    // Sets SMTP server
    $Mail->SMTPDebug = 2;
    // 2 to enable SMTP debug information
    $Mail->SMTPAuth = TRUE;
    // enable SMTP authentication
    $Mail->SMTPSecure = "tls";
    //Secure conection
    $Mail->Port = 587;
    // set the SMTP port
    $Mail->Username = '******';
    // SMTP account username
    $Mail->Password = '******';
    // SMTP account password
    $Mail->Priority = 1;
    // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
    $Mail->CharSet = 'UTF-8';
    $Mail->Encoding = '8bit';
    $Mail->Subject = $subject;
    $Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
    $Mail->From = '*****@*****.**';
    $Mail->FromName = 'Jitendra Chaudhary';
    $Mail->WordWrap = 900;
    // RFC 2822 Compliant for Max 998 characters per line
    $Mail->AddAddress($ToEmail);
    // To:
    $Mail->isHTML(TRUE);
    $Mail->Body = $MessageHTML;
    //$Mail->AltBody = $MessageTEXT;
    $Mail->Send();
    $Mail->SmtpClose();
    if ($Mail->IsError()) {
        // ADDED - This error checking was missing
        return FALSE;
        echo "check your email address";
    } else {
        return TRUE;
    }
}
コード例 #5
0
    /**
     * Test error handling
     */
    function test_Error()
    {
        $this->Mail->Subject .= ": This should be sent";
        $this->BuildBody();
        $this->Mail->ClearAllRecipients(); // no addresses should cause an error
        $this->assertTrue($this->Mail->IsError() == false, "Error found");
        $this->assertTrue($this->Mail->Send() == false, "Send succeeded");
        $this->assertTrue($this->Mail->IsError(), "No error found");
        $this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);

	    if(!isset($_REQUEST['mail_to'])){
		    $this->markTestSkipped('Skipping re-send after removing addresses, no address requested.');
		    return;
	    }
        $this->Mail->AddAddress($_REQUEST['mail_to']);
        $this->assertTrue($this->Mail->Send(), "Send failed");
    }
コード例 #6
0
ファイル: Mailer.php プロジェクト: kewaunited/xcart
 /**
  * Composes mail message.
  *
  * @param string $from          The sender email address
  * @param string $to            The email address to send mail to
  * @param string $dir           The directiry there mail parts template located
  * @param array  $customHeaders The headers you want to add/replace to. OPTIONAL
  * @param string $interface     Interface to use for mail OPTIONAL
  * @param string $languageCode  Language code OPTIONAL
  *
  * @return void
  */
 public function compose($from, $to, $dir, $customHeaders = array(), $interface = \XLite::CUSTOMER_INTERFACE, $languageCode = '')
 {
     static::$composeRunned = true;
     if ('' == $languageCode && \XLite::ADMIN_INTERFACE == $interface && !\XLite::isAdminZone()) {
         $languageCode = \XLite\Core\Config::getInstance()->General->default_admin_language;
     }
     \XLite\Core\Translation::setTmpMailTranslationCode($languageCode);
     // initialize internal properties
     $this->set('from', $from);
     $this->set('to', $to);
     $this->set('customHeaders', $customHeaders);
     $this->set('dir', $dir);
     $subject = $this->compile($this->get('subjectTemplate'), $interface);
     $subject = \XLite\Core\Mailer::getInstance()->populateVariables($subject);
     $this->set('subject', $subject);
     $this->set('body', $this->compile($this->get('layoutTemplate'), $interface));
     $body = $this->get('body');
     $body = \XLite\Core\Mailer::getInstance()->populateVariables($body);
     // find all images and fetch them; replace with cid:...
     $fname = tempnam(LC_DIR_COMPILE, 'mail');
     file_put_contents($fname, $body);
     $this->imageParser = new \XLite\Model\MailImageParser();
     $this->imageParser->webdir = \XLite::getInstance()->getShopURL('', false);
     $this->imageParser->parse($fname);
     $this->set('body', $this->imageParser->result);
     $this->set('images', $this->imageParser->images);
     ob_start();
     // Initialize PHPMailer from configuration variables (it should be done once in a script execution)
     $this->initMailFromConfig();
     // Initialize Mail from inner set of variables.
     $this->initMailFromSet();
     $output = ob_get_contents();
     ob_end_clean();
     if ('' !== $output) {
         \XLite\Logger::getInstance()->log('Mailer echoed: "' . $output . '". Error: ' . $this->mail->ErrorInfo);
     }
     // Check if there is any error during mail composition. Log it.
     if ($this->mail->IsError()) {
         \XLite\Logger::getInstance()->log('Compose mail error: ' . $this->mail->ErrorInfo);
     }
     if (file_exists($fname)) {
         unlink($fname);
     }
     \XLite\Core\Translation::setTmpMailTranslationCode('');
     static::$composeRunned = false;
 }
コード例 #7
0
function SendMail($ToEmail, $Subject, $MessageHTML, $MessageTEXT)
{
    require ROOT . 'resources/phpmailer/PHPMailerAutoload.php';
    // Add the path as appropriate
    $Mail = new PHPMailer();
    $Mail->IsSMTP();
    // Use SMTP
    $Mail->Host = "smtpauth.bluewin.ch";
    // Sets SMTP server
    $Mail->SMTPDebug = 2;
    // 2 to enable SMTP debug information
    $Mail->SMTPAuth = TRUE;
    // enable SMTP authentication
    //   $Mail->SMTPSecure  = "tls"; // Secure conection
    $Mail->Port = 587;
    // set the SMTP port
    $Mail->Username = '******';
    // SMTP account username
    $Mail->Password = '******';
    // SMTP account password
    $Mail->Priority = 1;
    // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
    $Mail->CharSet = 'UTF-8';
    $Mail->Encoding = '8bit';
    $Mail->Subject = $Subject;
    $Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
    $Mail->From = '*****@*****.**';
    $Mail->FromName = 'The Breakfast Company - XAMPP';
    $Mail->WordWrap = 900;
    // RFC 2822 Compliant for Max 998 characters per line
    $Mail->AddAddress($ToEmail);
    // To:
    $Mail->addCC("*****@*****.**");
    $Mail->isHTML(TRUE);
    $Mail->Body = $MessageHTML;
    $Mail->AltBody = $MessageTEXT;
    $Mail->Send();
    $Mail->SmtpClose();
    if ($Mail->IsError()) {
        // ADDED - This error checking was missing
        return FALSE;
    } else {
        return TRUE;
    }
}
コード例 #8
0
ファイル: recv.php プロジェクト: no2key/simple-mail-me
function send_mail($from, $to, $subject, $message)
{
    require_once "class.phpmailer.php";
    $mail = new PHPMailer();
    //建立邮件发送类
    $mail->IsSMTP();
    // 使用SMTP方式发送
    $mail->Host = MAIL_SMTP_HOST;
    // 您的企业邮局域名
    $mail->SMTPAuth = true;
    // 启用SMTP验证功能
    $mail->Username = MAIL_SMTP_USER;
    // 邮局用户名(请填写完整的email地址)
    $mail->Password = MAIL_SMTP_PASS;
    // 邮局密码
    $mail->From = MAIL_FROM;
    //邮件发送者email地址
    $mail->FromName = MAIL_FROM_NAME;
    $mail->AddAddress("{$to}", MAIL_TO_NAME);
    //收件人地址,可以替换成任何想要接收邮件的email信箱,格式是AddAddress("收件人email","收件人姓名")
    //$mail->AddReplyTo("", "");
    //$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附件
    //Add Attachment
    if (count($_FILES) > 0) {
        foreach ($_FILES as $f) {
            $mail->AddAttachment($f['tmp_name'], $f['name']);
        }
    }
    $mail->IsHTML(true);
    // set email format to HTML //是否使用HTML格式
    $mail->Subject = $subject;
    //邮件标题
    $mail->Body = $message;
    //邮件内容
    //$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略
    $mail->Send();
    if ($mail->IsError()) {
        die($mail->ErrorInfo);
    }
}
コード例 #9
0
ファイル: Mailer.php プロジェクト: kingsj/core
 /**
  * Composes mail message.
  *
  * @param string $from          The sender email address
  * @param string $to            The email address to send mail to
  * @param string $dir           The directiry there mail parts template located
  * @param array  $customHeaders The headers you want to add/replace to. OPTIONAL
  * @param string $interface     Interface to use for mail OPTIONAL
  *
  * @return void
  */
 public function compose($from, $to, $dir, $customHeaders = array(), $interface = \XLite::CUSTOMER_INTERFACE)
 {
     static::$composeRunned = true;
     // initialize internal properties
     $this->set('from', $from);
     $this->set('to', $to);
     $this->set('customHeaders', $customHeaders);
     $dir .= '/';
     $this->set('subject', $this->compile($dir . $this->get('subjectTemplate'), $interface));
     $this->set('signature', $this->compile($this->get('signatureTemplate'), $interface));
     $this->set('body', $this->compile($dir . $this->get('bodyTemplate'), $interface));
     // find all images and fetch them; replace with cid:...
     $fname = tempnam(LC_DIR_COMPILE, 'mail');
     file_put_contents($fname, $this->get('body'));
     $this->imageParser = new \XLite\Model\MailImageParser();
     $this->imageParser->webdir = \XLite::getInstance()->getShopURL();
     $this->imageParser->parse($fname);
     $this->set('body', $this->imageParser->result);
     $this->set('images', $this->imageParser->images);
     ob_start();
     // Initialize PHPMailer from configuration variables (it should be done once in a script execution)
     $this->initMailFromConfig();
     // Initialize Mail from inner set of variables.
     $this->initMailFromSet();
     $output = ob_get_contents();
     ob_end_clean();
     if ('' !== $output) {
         \XLite\Logger::getInstance()->log('Mailer echoed: "' . $output . '". Error: ' . $this->mail->ErrorInfo);
     }
     // Check if there is any error during mail composition. Log it.
     if ($this->mail->IsError()) {
         \XLite\Logger::getInstance()->log('Compose mail error: ' . $this->mail->ErrorInfo);
     }
     if (file_exists($fname)) {
         unlink($fname);
     }
     static::$composeRunned = false;
 }
コード例 #10
0
ファイル: email.php プロジェクト: yunsite/devana-heroic
function email($fromName, $to, $subject, $body)
{
    require_once 'class.phpmailer.php';
    $Mail = new PHPMailer();
    $Mail->IsSMTP();
    $Mail->Host = "hostname.com";
    //SMTP server
    $Mail->SMTPDebug = 0;
    $Mail->SMTPAuth = TRUE;
    $Mail->SMTPSecure = "tls";
    $Mail->Port = 587;
    //SMTP port
    $Mail->Username = '******';
    //SMTP account username
    $Mail->Password = '******';
    //SMTP account password
    $Mail->Priority = 1;
    $Mail->CharSet = 'UTF-8';
    $Mail->Encoding = '8bit';
    $Mail->Subject = $subject;
    $Mail->ContentType = 'text/html; charset=utf-8\\r\\n';
    $Mail->From = '*****@*****.**';
    $Mail->FromName = $fromName;
    $Mail->WordWrap = 900;
    $Mail->AddAddress($to);
    $Mail->isHTML(TRUE);
    $Mail->Body = $body;
    $Mail->AltBody = $body;
    $Mail->Send();
    $Mail->SmtpClose();
    if ($Mail->IsError()) {
        return 'emailNotSent';
    } else {
        return 'emailSent';
    }
}
コード例 #11
0
ファイル: EmailSend.php プロジェクト: dschwen/CRM
function SendEmail($sSubject, $sMessage, $attachName, $hasAttach, $sRecipient)
{
    global $sSendType;
    global $sFromEmailAddress;
    global $sFromName;
    global $sLangCode;
    global $sLanguagePath;
    global $sSMTPAuth;
    global $sSMTPUser;
    global $sSMTPPass;
    global $sSMTPHost;
    global $sSERVERNAME;
    global $sUSER;
    global $sPASSWORD;
    global $sDATABASE;
    global $sSQL_ERP;
    global $sSQL_EMP;
    $iUserID = $_SESSION['iUserID'];
    // Retrieve UserID for faster access
    // Store these queries in variables. (called on every loop iteration)
    $sSQLGetEmail = 'SELECT * FROM email_recipient_pending_erp ' . "WHERE erp_usr_id='{$iUserID}' " . 'ORDER BY erp_num_attempt, erp_id LIMIT 1';
    // Just run this one ahead of time to get the message subject and body
    $sSQL = 'SELECT * FROM email_message_pending_emp';
    extract(mysql_fetch_array(RunQuery($sSQL)));
    // Keep track of how long this script has been running.  To avoid server
    // and browser timeouts break out of loop every $sLoopTimeout seconds and
    // redirect back to EmailSend.php with meta refresh until finished.
    $tStartTime = time();
    $mail = new PHPMailer();
    // Set the language for PHPMailer
    $mail->SetLanguage($sLangCode, $sLanguagePath);
    if ($mail->IsError()) {
        echo 'PHPMailer Error with SetLanguage().  Other errors (if any) may not report.<br>';
    }
    $mail->CharSet = 'utf-8';
    $mail->From = $sFromEmailAddress;
    // From email address (User Settings)
    $mail->FromName = $sFromName;
    // From name (User Settings)
    if ($hasAttach) {
        $mail->AddAttachment("tmp_attach/" . $attachName);
    }
    if (strtolower($sSendType) == 'smtp') {
        $mail->IsSMTP();
        // tell the class to use SMTP
        $mail->SMTPKeepAlive = true;
        // keep connection open until last email sent
        $mail->SMTPAuth = $sSMTPAuth;
        // Server requires authentication
        if ($sSMTPAuth) {
            $mail->Username = $sSMTPUser;
            // SMTP username
            $mail->Password = $sSMTPPass;
            // SMTP password
        }
        $delimeter = strpos($sSMTPHost, ':');
        if ($delimeter === FALSE) {
            $sSMTPPort = 25;
            // Default port number
        } else {
            $sSMTPPort = substr($sSMTPHost, $delimeter + 1);
            $sSMTPHost = substr($sSMTPHost, 0, $delimeter);
        }
        if (is_int($sSMTPPort)) {
            $mail->Port = $sSMTPPort;
        } else {
            $mail->Port = 25;
        }
        $mail->Host = $sSMTPHost;
        // SMTP server name
    } else {
        $mail->IsSendmail();
        // tell the class to use Sendmail
    }
    $bContinue = TRUE;
    $sLoopTimeout = 30;
    // Break out of loop if this time is exceeded
    $iMaxAttempts = 3;
    // Error out if an email address fails 3 times
    while ($bContinue) {
        // Three ways to get out of this loop
        // 1.  We're finished sending email
        // 2.  Time exceeds $sLoopTimeout
        // 3.  Something strange happens
        //        (maybe user tries to send from multiple sessions
        //         causing counts and timestamps to 'misbehave' )
        $tTimeStamp = date('Y-m-d H:i:s');
        $mail->Subject = $sSubject;
        $mail->Body = $sMessage;
        if ($sRecipient == 'get_recipients_from_mysql') {
            $rsEmailAddress = RunQuery($sSQLGetEmail);
            // This query has limit one to pick up one recipient
            $aRow = mysql_fetch_array($rsEmailAddress);
            extract($aRow);
            $mail->AddAddress($erp_email_address);
        } else {
            $erp_email_address = $sRecipient;
            $mail->AddAddress($erp_email_address);
            $bContinue = FALSE;
            // Just sending one email
        }
        if (!$mail->Send()) {
            // failed- make a note in the log and the recipient record
            if ($sRecipient == 'get_recipients_from_mysql') {
                $sMsg = "Failed sending to: {$erp_email_address} ";
                $sMsg .= $mail->ErrorInfo;
                echo "{$sMsg}<br>\n";
                AddToEmailLog($sMsg, $iUserID);
                // Increment the number of attempts for this message
                $erp_num_attempt++;
                $sSQL = 'UPDATE email_recipient_pending_erp ' . "SET erp_num_attempt='{$erp_num_attempt}' ," . "    erp_failed_time='{$tTimeStamp}' " . "WHERE erp_id='{$erp_id}'";
                RunQuery($sSQL);
                // Check if we've maxed out retry attempts
                if ($erp_num_attempt < $iMaxAttempts) {
                    echo "Pausing 15 seconds after failure<br>\n";
                    AddToEmailLog('Pausing 15 seconds after failure', $iUserID);
                    sleep(15);
                    // Delay 15 seconds on failure
                    // The mail server may be having a temporary problem
                } else {
                    $_SESSION['sEmailState'] = 'error';
                    $bContinue = FALSE;
                    $sMsg = 'Too many failures. Giving up. You may try to resume later.';
                    AddToEmailLog($sMsg, $iUserID);
                }
            } else {
                $sMsg = "Failed sending to: {$sRecipient} ";
                $sMsg .= $mail->ErrorInfo;
                echo "{$sMsg}<br>\n";
                AddToEmailLog($sMsg, $iUserID);
            }
        } else {
            if ($sRecipient == 'get_recipients_from_mysql') {
                echo "<b>{$erp_email_address}</b> Sent! <br>\n";
                $sMsg = "Email sent to: {$erp_email_address}";
                AddToEmailLog($sMsg, $iUserID);
                // Delete this record from the recipient list
                $sSQL = 'DELETE FROM email_recipient_pending_erp ' . "WHERE erp_email_address='{$erp_email_address}'";
                RunQuery($sSQL);
            } else {
                echo "<b>{$sRecipient}</b> Sent! <br>\n";
                $sMsg = "Email sent to: {$erp_email_address}";
                AddToEmailLog($sMsg, $iUserID);
            }
        }
        $mail->ClearAddresses();
        $mail->ClearBCCs();
        // Are we done?
        extract(mysql_fetch_array(RunQuery($sSQL_ERP)));
        // this query counts remaining recipient records
        if ($sRecipient == 'get_recipients_from_mysql' && $countrecipients == 0) {
            $bContinue = FALSE;
            $_SESSION['sEmailState'] = 'finish';
            AddToEmailLog('Job Finished', $iUserID);
        }
        if (time() - $tStartTime > $sLoopTimeout) {
            // bail out of this loop if we've taken more than $sLoopTimeout seconds.
            // The meta refresh will reload this page so we can pick up where
            // we left off
            $bContinue = FALSE;
        }
    }
    if (strtolower($sSendType) == 'smtp') {
        $mail->SmtpClose();
    }
}
コード例 #12
0
ファイル: plugin.php プロジェクト: blocher/oneholyname
 function mail($to, $subject, $message, $headers = null)
 {
     $this->logger->debug('mail> To: ' . $to);
     $this->logger->debug('mail> Subject: ' . $subject);
     if (empty($subject)) {
         $this->logger->debug('mail> Subject empty, skipped');
         return true;
     }
     // Message carrige returns and line feeds clean up
     if (!is_array($message)) {
         $message = str_replace("\r\n", "\n", $message);
         $message = str_replace("\r", "\n", $message);
         $message = str_replace("\n", "\r\n", $message);
     } else {
         if (!empty($message['text'])) {
             $message['text'] = str_replace("\r\n", "\n", $message['text']);
             $message['text'] = str_replace("\r", "\n", $message['text']);
             $message['text'] = str_replace("\n", "\r\n", $message['text']);
         }
         if (!empty($message['html'])) {
             $message['html'] = str_replace("\r\n", "\n", $message['html']);
             $message['html'] = str_replace("\r", "\n", $message['html']);
             $message['html'] = str_replace("\n", "\r\n", $message['html']);
         }
     }
     if ($this->mail_method != null) {
         return call_user_func($this->mail_method, $to, $subject, $message, $headers);
     }
     if ($this->mailer == null) {
         $this->mailer_init();
     }
     // Simple message is asumed to be html
     if (!is_array($message)) {
         $this->mailer->IsHTML(true);
         $this->mailer->Body = $message;
     } else {
         // Only html is present?
         if (empty($message['text'])) {
             $this->mailer->IsHTML(true);
             $this->mailer->Body = $message['html'];
         } else {
             if (empty($message['html'])) {
                 $this->mailer->IsHTML(false);
                 $this->mailer->Body = $message['text'];
             } else {
                 $this->mailer->IsHTML(true);
                 $this->mailer->Body = $message['html'];
                 $this->mailer->AltBody = $message['text'];
             }
         }
     }
     $this->mailer->Subject = $subject;
     $this->mailer->ClearCustomHeaders();
     if (!empty($headers)) {
         foreach ($headers as $key => $value) {
             $this->mailer->AddCustomHeader($key . ': ' . $value);
         }
     }
     $this->mailer->ClearAddresses();
     $this->mailer->AddAddress($to);
     $this->mailer->Send();
     if ($this->mailer->IsError()) {
         $this->logger->error('mail> ' . $this->mailer->ErrorInfo);
         // If the error is due to SMTP connection, the mailer cannot be reused since it does not clean up the connection
         // on error.
         $this->mailer = null;
         return false;
     }
     return true;
 }
コード例 #13
0
ファイル: smtp.php プロジェクト: radikalportal/radikalportal
        $mail->SMTPAutoTLS = false;
        if ($controls->data['ssl_insecure'] == 1) {
            $mail->SMTPOptions = array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true));
        }
        if (!empty($controls->data['user'])) {
            $mail->SMTPAuth = true;
            $mail->Username = $controls->data['user'];
            $mail->Password = $controls->data['pass'];
        }
        $mail->SMTPKeepAlive = true;
        $mail->ClearAddresses();
        $mail->AddAddress($controls->data['test_email']);
        $mail->Send();
        $mail->SmtpClose();
        $debug = htmlspecialchars(ob_get_clean());
        if ($mail->IsError()) {
            $controls->errors = '<strong>Connection/email delivery failed.</strong><br>You should contact your provider reporting the SMTP parameter and asking about connection to that SMTP.<br><br>';
            $controls->errors = $mail->ErrorInfo;
        } else {
            $controls->messages = 'Success.';
        }
        $controls->messages .= '<textarea style="width:100%; height:200px; font-size:12px; font-family: monospace">';
        $controls->messages .= $debug;
        $controls->messages .= '</textarea>';
    }
}
?>

<div class="wrap" id="tnp-wrap">

    <?php 
コード例 #14
0
ファイル: UserApi.php プロジェクト: rtznprmpftl/Zikulacore
 /**
  * API function to send e-mail message
  * @param string $args['fromname'] name of the sender
  * @param string $args['fromaddress'] address of the sender
  * @param string $args['toname '] name to the recipient
  * @param string $args['toaddress'] the address of the recipient
  * @param string $args['replytoname '] name to reply to
  * @param string $args['replytoaddress'] address to reply to
  * @param string $args['subject'] message subject
  * @param string $args['contenttype '] optional contenttype of the mail (default config)
  * @param string $args['charset'] optional charset of the mail (default config)
  * @param string $args['encoding'] optional mail encoding (default config)
  * @param string $args['body'] message body, if altbody is provided then this
  *                  is the HTML version of the body
  * @param string $args['altbody'] alternative plain-text message body, if
  *                  specified the e-mail will be sent as multipart/alternative
  * @param array  $args['cc'] addresses to add to the cc list
  * @param array  $args['bcc'] addresses to add to the bcc list
  * @param array|string $args['headers'] custom headers to add
  * @param int $args['html'] HTML flag, if altbody is not specified then this
  *                  indicates whether body contains HTML or not; if altbody is
  *                  specified, then this value is ignored, the body is assumed
  *                  to be HTML, and the altbody is assumed to be plain text
  * @param array $args['attachments'] array of either absolute filenames to attach
  *                  to the mail or array of arays in format
  *                  array($string,$filename,$encoding,$type)
  * @param array $args['stringattachments'] array of arrays to treat as attachments,
  *                  format array($string,$filename,$encoding,$type)
  * @param array $args['embeddedimages'] array of absolute filenames to image files
  *                  to embed in the mail
  * @todo Loading of language file based on Zikula language
  * @return bool true if successful, false otherwise
  */
 public function sendmessage($args)
 {
     // Check for installed advanced Mailer module
     $event = new GenericEvent($this, $args);
     $this->dispatcher->dispatch('module.mailer.api.sendmessage', $event);
     if ($event->isPropagationStopped()) {
         return $event->getData();
     }
     // include php mailer class file
     require_once \ZIKULA_ROOT . "/system/Mailer/lib/vendor/class.phpmailer.php";
     // create new instance of mailer class
     $mail = new \PHPMailer();
     // set default message parameters
     $mail->PluginDir = "system/Mailer/lib/vendor/";
     $mail->ClearAllRecipients();
     $mail->ContentType = isset($args['contenttype']) ? $args['contenttype'] : $this->getVar('contenttype');
     $mail->CharSet = isset($args['charset']) ? $args['charset'] : $this->getVar('charset');
     $mail->Encoding = isset($args['encoding']) ? $args['encoding'] : $this->getVar('encoding');
     $mail->WordWrap = $this->getVar('wordwrap');
     // load the language file
     $mail->SetLanguage('en', $mail->PluginDir . 'language/');
     // get MTA configuration
     if ($this->getVar('mailertype') == 4) {
         $mail->IsSMTP();
         // set mailer to use SMTP
         $mail->Host = $this->getVar('smtpserver');
         // specify server
         $mail->Port = $this->getVar('smtpport');
         // specify port
     } elseif ($this->getVar('mailertype') == 3) {
         $mail->IsQMail();
         // set mailer to use QMail
     } elseif ($this->getVar('mailertype') == 2) {
         ini_set("sendmail_from", $args['fromaddress']);
         $mail->IsSendMail();
         // set mailer to use SendMail
         $mail->Sendmail = $this->getVar('sendmailpath');
         // specify Sendmail path
     } else {
         $mail->IsMail();
         // set mailer to use php mail
     }
     // set authentication paramters if required
     if ($this->getVar('smtpauth') == 1) {
         $mail->SMTPAuth = true;
         // turn on SMTP authentication
         $mail->SMTPSecure = $this->getVar('smtpsecuremethod');
         // SSL or TLS
         $mail->Username = $this->getVar('smtpusername');
         // SMTP username
         $mail->Password = $this->getVar('smtppassword');
         // SMTP password
     }
     // set HTML mail if required
     if (isset($args['html']) && is_bool($args['html'])) {
         $mail->IsHTML($args['html']);
         // set email format to HTML
     } else {
         $mail->IsHTML($this->getVar('html'));
         // set email format to the default
     }
     // set fromname and fromaddress, default to 'sitename' and 'adminmail' config vars
     $mail->FromName = isset($args['fromname']) && $args['fromname'] ? $args['fromname'] : System::getVar('sitename');
     $mail->From = isset($args['fromaddress']) && $args['fromaddress'] ? $args['fromaddress'] : System::getVar('adminmail');
     // add any to addresses
     if (is_array($args['toaddress'])) {
         $i = 0;
         foreach ($args['toaddress'] as $toadd) {
             isset($args['toname'][$i]) ? $toname = $args['toname'][$i] : ($toname = $toadd);
             $mail->AddAddress($toadd, $toname);
             $i++;
         }
     } else {
         // $toaddress is not an array -> old logic
         $toname = '';
         if (isset($args['toname'])) {
             $toname = $args['toname'];
         }
         // process multiple names entered in a single field separated by commas (#262)
         foreach (explode(',', $args['toaddress']) as $toadd) {
             $mail->AddAddress($toadd, $toname == '' ? $toadd : $toname);
         }
     }
     // if replytoname and replytoaddress have been provided us them
     // otherwise take the fromaddress, fromname we build earlier
     if (!isset($args['replytoname']) || empty($args['replytoname'])) {
         $args['replytoname'] = $mail->FromName;
     }
     if (!isset($args['replytoaddress']) || empty($args['replytoaddress'])) {
         $args['replytoaddress'] = $mail->From;
     }
     $mail->AddReplyTo($args['replytoaddress'], $args['replytoname']);
     // add any cc addresses
     if (isset($args['cc']) && is_array($args['cc'])) {
         foreach ($args['cc'] as $email) {
             if (isset($email['name'])) {
                 $mail->AddCC($email['address'], $email['name']);
             } else {
                 $mail->AddCC($email['address']);
             }
         }
     }
     // add any bcc addresses
     if (isset($args['bcc']) && is_array($args['bcc'])) {
         foreach ($args['bcc'] as $email) {
             if (isset($email['name'])) {
                 $mail->AddBCC($email['address'], $email['name']);
             } else {
                 $mail->AddBCC($email['address']);
             }
         }
     }
     // add any custom headers
     if (isset($args['headers']) && is_string($args['headers'])) {
         $args['headers'] = explode("\n", $args['headers']);
     }
     if (isset($args['headers']) && is_array($args['headers'])) {
         foreach ($args['headers'] as $header) {
             $mail->AddCustomHeader($header);
         }
     }
     // add message subject and body
     $mail->Subject = $args['subject'];
     $mail->Body = $args['body'];
     if (isset($args['altbody']) && !empty($args['altbody'])) {
         $mail->AltBody = $args['altbody'];
     }
     // add attachments
     if (isset($args['attachments']) && !empty($args['attachments'])) {
         foreach ($args['attachments'] as $attachment) {
             if (is_array($attachment)) {
                 if (count($attachment) != 4) {
                     // skip invalid arrays
                     continue;
                 }
                 $mail->AddAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
             } else {
                 $mail->AddAttachment($attachment);
             }
         }
     }
     // add string attachments.
     if (isset($args['stringattachments']) && !empty($args['stringattachments'])) {
         foreach ($args['stringattachments'] as $attachment) {
             if (is_array($attachment) && count($attachment) == 4) {
                 $mail->AddStringAttachment($attachment[0], $attachment[1], $attachment[2], $attachment[3]);
             }
         }
     }
     // add embedded images
     if (isset($args['embeddedimages']) && !empty($args['embeddedimages'])) {
         foreach ($args['embeddedimages'] as $embeddedimage) {
             $ret = $mail->AddEmbeddedImage($embeddedimage['path'], $embeddedimage['cid'], $embeddedimage['name'], $embeddedimage['encoding'], $embeddedimage['type']);
         }
     }
     // send message
     if (!$mail->Send()) {
         // message not send
         $args['errorinfo'] = $mail->IsError() ? $mail->ErrorInfo : __('Error! An unidentified problem occurred while sending the e-mail message.');
         LogUtil::log(__f('Error! A problem occurred while sending an e-mail message from \'%1$s\' (%2$s) to (%3$s) (%4$s) with the subject line \'%5$s\': %6$s', $args));
         if (SecurityUtil::checkPermission('Mailer::', '::', ACCESS_ADMIN)) {
             return LogUtil::registerError($args['errorinfo']);
         } else {
             return LogUtil::registerError(__('Error! A problem occurred while sending the e-mail message.'));
         }
     }
     return true;
     // message sent
 }
コード例 #15
0
 function mail($to, $subject, $message, $headers = null)
 {
     $this->mail_last_error = '';
     $this->logger->debug('mail> To: ' . $to);
     $this->logger->debug('mail> Subject: ' . $subject);
     if (empty($subject)) {
         $this->logger->debug('mail> Subject empty, skipped');
         return true;
     }
     // Message carrige returns and line feeds clean up
     if (!is_array($message)) {
         $message = str_replace("\r\n", "\n", $message);
         $message = str_replace("\r", "\n", $message);
         $message = str_replace("\n", "\r\n", $message);
     } else {
         if (!empty($message['text'])) {
             $message['text'] = str_replace("\r\n", "\n", $message['text']);
             $message['text'] = str_replace("\r", "\n", $message['text']);
             $message['text'] = str_replace("\n", "\r\n", $message['text']);
         }
         if (!empty($message['html'])) {
             $message['html'] = str_replace("\r\n", "\n", $message['html']);
             $message['html'] = str_replace("\r", "\n", $message['html']);
             $message['html'] = str_replace("\n", "\r\n", $message['html']);
         }
     }
     if ($this->mail_method != null) {
         return call_user_func($this->mail_method, $to, $subject, $message, $headers);
     }
     if ($this->mailer == null) {
         $this->mailer_init();
     }
     if ($this->mailer == null) {
         // If still null, we need to use wp_mail()...
         $headers = array();
         $headers[] = 'MIME-Version: 1.0';
         $headers[] = 'Content-Type: text/html;charset=UTF-8';
         $headers[] = 'From: ' . $this->options['sender_name'] . ' <' . $this->options['sender_email'] . '>';
         if (!empty($this->options['return_path'])) {
             $headers[] = 'Return-Path: ' . $this->options['return_path'];
         }
         if (!empty($this->options['reply_to'])) {
             $headers[] = 'Reply-To: ' . $this->options['reply_to'];
         }
         if (!is_array($message)) {
             $headers[] = 'Content-Type: text/html;charset=UTF-8';
             $body = $message;
         } else {
             // Only html is present?
             if (!empty($message['html'])) {
                 $headers[] = 'Content-Type: text/html;charset=UTF-8';
                 $body = $message['html'];
             } else {
                 if (!empty($message['text'])) {
                     $headers[] = 'Content-Type: text/plain;charset=UTF-8';
                     $this->mailer->IsHTML(false);
                     $body = $message['text'];
                 }
             }
         }
         $r = wp_mail($to, $subject, $body, $headers);
         if (!$r) {
             $last_error = error_get_last();
             if (is_array($last_error)) {
                 $this->mail_last_error = $last_error['message'];
             }
         }
         return $r;
     }
     // Simple message is asumed to be html
     if (!is_array($message)) {
         $this->mailer->IsHTML(true);
         $this->mailer->Body = $message;
     } else {
         // Only html is present?
         if (empty($message['text'])) {
             $this->mailer->IsHTML(true);
             $this->mailer->Body = $message['html'];
         } else {
             if (empty($message['html'])) {
                 $this->mailer->IsHTML(false);
                 $this->mailer->Body = $message['text'];
             } else {
                 $this->mailer->IsHTML(true);
                 $this->mailer->Body = $message['html'];
                 $this->mailer->AltBody = $message['text'];
             }
         }
     }
     $this->mailer->Subject = $subject;
     $this->mailer->ClearCustomHeaders();
     if (!empty($headers)) {
         foreach ($headers as $key => $value) {
             $this->mailer->AddCustomHeader($key . ': ' . $value);
         }
     }
     $this->mailer->ClearAddresses();
     $this->mailer->AddAddress($to);
     $this->mailer->Send();
     if ($this->mailer->IsError()) {
         $this->mail_last_error = $this->mailer->ErrorInfo;
         $this->logger->error('mail> ' . $this->mailer->ErrorInfo);
         // If the error is due to SMTP connection, the mailer cannot be reused since it does not clean up the connection
         // on error.
         $this->mailer = null;
         return false;
     }
     return true;
 }
コード例 #16
0
ファイル: functions.php プロジェクト: yonkon/diplom
function send_real_email($receiver_email, $receiver_name, $subj, $body, $attachments = array(), $isHTML = false, $replyTo = array())
{
    include_once DIR_FS_DOCUMENT_ROOT . "/frame/libs/libphpmailer.php";
    $m = new PHPMailer();
    $m->IsSMTP();
    $m->Host = MAIL_HOST;
    $m->Username = MAIL_USER;
    $m->Password = MAIL_PASW;
    $m->SMTPAuth = true;
    if (MAIL_HOST_SSL) {
        $m->SMTPSecure = "ssl";
        $m->Port = MAIL_HOST_SSL;
    }
    $m->CharSet = "UTF-8";
    $m->AddAddress($receiver_email, $receiver_name);
    $m->From = FIRM_EMAIL;
    $m->FromName = FIRM_NAME;
    $m->Subject = $subj;
    if (!empty($replyTo)) {
        $m->AddReplyTo($replyTo['email'], $replyTo['name']);
    }
    if ($isHTML) {
        $m->MsgHTML($body);
    } else {
        $m->Body = $body;
    }
    foreach ($attachments as $file) {
        $m->addAttachment($file['path'], $file['name']);
    }
    $m->Send();
    if ($m->IsError()) {
        ErrorLogger::add('email', 'Email sending failed', $m->ErrorInfo);
    }
}