validateAddress() public static method

Check that a string looks like an email address.
public static validateAddress ( string $address, string | callable $patternselect = null ) : boolean
$address string The email address to check
$patternselect string | callable A selector for the validation pattern to use : * `auto` Pick best pattern automatically; * `pcre8` Use the squiloople.com pattern, requires PCRE > 8.0, PHP >= 5.3.2, 5.2.14; * `pcre` Use old PCRE implementation; * `php` Use PHP built-in FILTER_VALIDATE_EMAIL; * `html5` Use the pattern given by the HTML5 spec for 'email' type form input elements. * `noregex` Don't use a regex: super fast, really dumb. Alternatively you may pass in a callable to inject your own validator, for example: PHPMailer::validateAddress('user@example.com', function($address) { return (strpos($address, '@') !== false); }); You can also set the PHPMailer::$validator static to a callable, allowing built-in methods to use your validator.
return boolean
Example #1
0
File: core.php Project: seifsg/eums
 public function verify_emails($emails)
 {
     $invalid_emails_count = 0;
     $exists = 0;
     require_once 'PHPMailer-master/class.phpmailer.php';
     $emails = self::emails_to_array($emails);
     $count_emails = count($emails);
     for ($i = 0; $i < $count_emails; $i++) {
         if (!PHPMailer::validateAddress($emails[$i])) {
             $invalid_emails_count++;
             unset($emails[$i]);
         }
     }
     for ($i = 0; $i < $count_emails; $i++) {
         $exists_in = $this->_db->prepare("SELECT COUNT(*) FROM emails WHERE email = '{$emails[$i]}'");
         $result = $exists_in->execute();
         $exists_in = $exists_in->fetchALL(PDO::FETCH_ASSOC);
         $exists_in = implode('', $exists_in[0]);
         if ($exists_in > 0) {
             $exists++;
             unset($emails[$i]);
         }
     }
     usort($emails, 'strnatcmp');
     return array($emails, $invalid_emails_count, $count_emails - $invalid_emails_count - $exists, $exists);
 }
 /**
  * @inheritdoc
  */
 public static function validateAddress($address, $patternselect = null)
 {
     if ($patternselect === null) {
         $patternselect = self::$patternSelect;
     }
     return parent::validateAddress($address, $patternselect);
 }
Example #3
0
    /**
     * 发送邮件
     * @param string $subject           主题
     * @param string $content           邮件正文  
     * @param string $toAddress         收件人地址
     * @param string $toName            收件人姓名
     * @param string $fromAddress       发件人地址
     * @param string $fromName          发件人姓名
     * @param array $attach             邮件附件
     *                  path        附件地址
     *                  name        附件名称
     * @param string $replayAddress     回复地址
     * @param string $replayName        回复名称
     * @param array $cc                 抄送人地址
     * @param array $bcc                密送人地址
     * @return boolean                  是否发送成功
     */
    public function sendMail($subject, $content, $toAddress, $toName, $fromAddress, $fromName, $attach = array(), $replayAddress = '', $replayName = '', $cc = array(), $bcc = array())
    {
        if (!\PHPMailer::validateAddress($toAddress)) {
            $this->errMsg = '收件人地址' . $toAddress . '不合法,邮件发送失败';
            return FALSE;
        }
        if (!empty($replayAddress)) {
            $this->_mail->addReplyTo($replayAddress, $replayName);
        }
        if (C('MAIL_TYPE') == 'SMTP') {
            //SMTP方式发送邮件,发信人为SMTP账号
            $this->_mail->From = C('SMTP_PARAM.USERNAME');
        } else {
            $this->_mail->From = $fromAddress;
        }
        $this->_mail->FromName = $fromName;
        $this->_mail->addAddress($toAddress, $toName);
        //添加抄送人
        if (!empty($cc) && is_array($cc)) {
            foreach ($cc as $ccemail) {
                $this->_mail->addCC($ccemail);
            }
        }
        //添加密送地址
        if (!empty($bcc) && is_array($bcc)) {
            foreach ($bcc as $bccemail) {
                $this->_mail->addBCC($bccemail);
            }
        }
        $this->_mail->Subject = $subject;
        $body = <<<EOT
{$content}
EOT;
        //定义每行字符数
        $this->_mail->WordWrap = 80;
        $this->_mail->msgHTML($body, dirname(__FILE__), true);
        //Create message bodies and embed images
        //添加附件文件
        if (!empty($attach) && is_array($attach)) {
            foreach ($attach as $attachValue) {
                if (isset($attachValue['path']) && is_file($attachValue['path'])) {
                    $attachName = isset($attachValue['name']) ? $attachValue['name'] : '';
                    $this->_mail->addAttachment($attachValue['path'], $attachName);
                }
            }
        }
        try {
            $sendResult = $this->_mail->send();
            if (!$sendResult) {
                $this->errMsg = $this->_mail->ErrorInfo;
            }
            return $sendResult;
        } catch (\phpmailerException $e) {
            $this->errMsg = $e->getMessage();
            return false;
        }
    }
 /**
  * Test email address validation
  * Test addresses obtained from http://isemail.info
  * Some failing cases commented out that are apparently up for debate!
  */
 public function testValidate()
 {
     $validaddresses = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '"first\\"last"@iana.org', '"first@last"@iana.org', '"first\\last"@iana.org', 'first.last@[12.34.56.78]', 'first.last@[IPv6:::12.34.56.78]', 'first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]', 'first.last@[IPv6:::1111:2222:3333:4444:5555:6666]', 'first.last@[IPv6:1111:2222:3333::4444:5555:6666]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666::]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"first\\last"@iana.org', 'first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]', 'first.last@example.123', 'first.last@com', '"Abc\\@def"@iana.org', '"Fred\\ Bloggs"@iana.org', '"Joe.\\Blow"@iana.org', '"Abc@def"@iana.org', '"Fred Bloggs"@iana.org', '*****@*****.**', 'customer/department=shipping@iana.org', '$A12345@iana.org', '!def!xyz%abc@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"Doug \\"Ace\\" L."@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 't*est@iana.org', '+1~1+@iana.org', '{_test_}@iana.org', '"[[ test ]]"@iana.org', '*****@*****.**', '"test.test"@iana.org', 'test."test"@iana.org', '"test@test"@iana.org', 'test@123.123.123.x123', 'test@123.123.123.123', 'test@[123.123.123.123]', '*****@*****.**', '*****@*****.**', '"test\\test"@iana.org', 'test@example', '"test\\blah"@iana.org', '"test\\blah"@iana.org', '"test\\"blah"@iana.org', 'customer/department@iana.org', '*****@*****.**', '~@iana.org', '"Austin@Powers"@iana.org', '*****@*****.**', '"Ima.Fool"@iana.org', '"Ima Fool"@iana.org', '"first"."last"@iana.org', '"first".middle."last"@iana.org', '"first"*****@*****.**', 'first."last"@iana.org', '"first"."middle"."last"@iana.org', '"first.middle"."last"@iana.org', '"first.middle.last"@iana.org', '"first..last"@iana.org', '"first\\"last"@iana.org', 'first."mid\\dle"."last"@iana.org', '"test blah"@iana.org', '(foo)cal(bar)@(baz)iamcal.com(quux)', 'cal@iamcal(woo).(yay)com', 'cal(woo(yay)hoopla)@iamcal.com', 'cal(foo\\@bar)@iamcal.com', 'cal(foo\\)bar)@iamcal.com', 'first().last@iana.org', 'pete(his account)@silly.test(his host)', 'c@(Chris\'s host.)public.example', 'jdoe@machine(comment). example', '1234 @ local(blah) .machine .example', 'first(abc.def).last@iana.org', 'first(a"bc.def).last@iana.org', 'first.(")middle.last(")@iana.org', 'first(abc\\(def)@iana.org', 'first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com', 'a(a(b(c)d(e(f))g)h(i)j)@iana.org', '*****@*****.**', 'a@b', '*****@*****.**', 'aaa@[123.123.123.123]', 'a@bar', '*****@*****.**', '+@b.c', '*****@*****.**', '*****@*****.**', '"hello my name is"@stutter.com', '"Test \\"Fail\\" Ing"@iana.org', '*****@*****.**', '*****@*****.**', 'foobar@192.168.0.1', '"Joe\\Blow"@iana.org', 'HM2Kinsists@(that comments are allowed)this.is.ok', 'user%uucp!path@berkeley.edu', 'first.last @iana.org', 'cdburgess+!#$%&\'*-/=?+_{}|~test@gmail.com', 'first.last@[IPv6:::a2:a3:a4:b1:b2:b3:b4]', 'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3::]', 'first.last@[IPv6:::]', 'first.last@[IPv6:::b4]', 'first.last@[IPv6:::b3:b4]', 'first.last@[IPv6:a1::b4]', 'first.last@[IPv6:a1::]', 'first.last@[IPv6:a1:a2::]', 'first.last@[IPv6:0123:4567:89ab:cdef::]', 'first.last@[IPv6:0123:4567:89ab:CDEF::]', 'first.last@[IPv6:::a3:a4:b1:ffff:11.22.33.44]', 'first.last@[IPv6:::a2:a3:a4:b1:ffff:11.22.33.44]', 'first.last@[IPv6:a1:a2:a3:a4::11.22.33.44]', 'first.last@[IPv6:a1:a2:a3:a4:b1::11.22.33.44]', 'first.last@[IPv6:a1::11.22.33.44]', 'first.last@[IPv6:a1:a2::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:CDEF::11.22.33.44]', 'first.last@[IPv6:a1::b2:11.22.33.44]', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     $invalidaddresses = array('first.last@sub.do,com', 'first\\@last@iana.org', '123456789012345678901234567890123456789012345678901234567890' . '@12345678901234567890123456789012345678901234 [...]', 'first.last', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"first"last"@iana.org', '"""@iana.org', '"\\"@iana.org', 'first\\@last@iana.org', 'first.last@', 'x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.' . 'x23456789.x23456789.x23456789.x23 [...]', 'first.last@[.12.34.56.78]', 'first.last@[12.34.56.789]', 'first.last@[::12.34.56.78]', 'first.last@[IPv5:::12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]', 'first.last@[IPv6:1111:2222::3333::4444:5555:6666]', 'first.last@[IPv6:1111:2222:333x::4444:5555]', 'first.last@[IPv6:1111:2222:33333::4444:5555]', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'abc\\@def@iana.org', 'abc\\@iana.org', 'Doug\\ \\"Ace\\"\\ Lovell@iana.org', 'abc@def@iana.org', 'abc\\@def@iana.org', 'abc\\@iana.org', '@iana.org', 'doug@', '"*****@*****.**', 'ote"@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '"Doug "Ace" L."@iana.org', 'Doug\\ \\"Ace\\"\\ L\\.@iana.org', 'hello world@iana.org', 'gatsby@f.sc.ot.t.f.i.tzg.era.l.d.', 'test.iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'test@test@iana.org', 'test@@iana.org', '-- test --@iana.org', '[test]@iana.org', '"test"test"@iana.org', '()[]\\;:,><@iana.org', 'test@.', 'test@example.', 'test@.org', 'test@12345678901234567890123456789012345678901234567890123456789012345678901234567890' . '12345678901234567890 [...]', 'test@[123.123.123.123', 'test@123.123.123.123]', 'NotAnEmail', '@NotAnEmail', '"test"blah"@iana.org', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'Ima Fool@iana.org', 'phil.h\\@\\@ck@haacked.com', 'foo@[\\1.2.3.4]', 'first\\last@iana.org', 'Abc\\@def@iana.org', 'Fred\\ Bloggs@iana.org', 'Joe.\\Blow@iana.org', 'first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]', '{^c\\@**Dog^}@cartoon.com', 'cal(foo(bar)@iamcal.com', 'cal(foo)bar)@iamcal.com', 'cal(foo\\)@iamcal.com', 'first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789' . '01234567890123456789012 [...]', 'first(middle)last@iana.org', 'first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example' . '(abc("def".ghi).mno). [...]', 'a(a(b(c)d(e(f))g)(h(i)j)@iana.org', '.@', '@bar.com', '@@bar.com', 'aaa.com', 'aaa@.com', 'aaa@.123', 'aaa@[123.123.123.123]a', 'aaa@[123.123.123.333]', 'a@bar.com.', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', 'invalid@about.museum-', '*****@*****.**', '"Unicode NULL' . chr(0) . '"@char.com', 'Unicode NULL' . chr(0) . '@char.com', 'first.last@[IPv6::]', 'first.last@[IPv6::::]', 'first.last@[IPv6::b4]', 'first.last@[IPv6::::b4]', 'first.last@[IPv6::b3:b4]', 'first.last@[IPv6::::b3:b4]', 'first.last@[IPv6:a1:::b4]', 'first.last@[IPv6:a1:]', 'first.last@[IPv6:a1:::]', 'first.last@[IPv6:a1:a2:]', 'first.last@[IPv6:a1:a2:::]', 'first.last@[IPv6::11.22.33.44]', 'first.last@[IPv6::::11.22.33.44]', 'first.last@[IPv6:a1:11.22.33.44]', 'first.last@[IPv6:a1:::11.22.33.44]', 'first.last@[IPv6:a1:a2:::11.22.33.44]', 'first.last@[IPv6:0123:4567:89ab:cdef::11.22.33.xx]', 'first.last@[IPv6:0123:4567:89ab:CDEFF::11.22.33.44]', 'first.last@[IPv6:a1::a4:b1::b4:11.22.33.44]', 'first.last@[IPv6:a1::11.22.33]', 'first.last@[IPv6:a1::11.22.33.44.55]', 'first.last@[IPv6:a1::b211.22.33.44]', 'first.last@[IPv6:a1::b2::11.22.33.44]', 'first.last@[IPv6:a1::b3:]', 'first.last@[IPv6::a2::b4]', 'first.last@[IPv6:a1:a2:a3:a4:b1:b2:b3:]', 'first.last@[IPv6::a2:a3:a4:b1:b2:b3:b4]', 'first.last@[IPv6:a1:a2:a3:a4::b1:b2:b3:b4]');
     $goodfails = array();
     foreach ($validaddresses as $address) {
         if (!PHPMailer::validateAddress($address)) {
             $goodfails[] = $address;
         }
     }
     $badpasses = array();
     foreach ($invalidaddresses as $address) {
         if (PHPMailer::validateAddress($address)) {
             $badpasses[] = $address;
         }
     }
     $err = '';
     if (count($goodfails) > 0) {
         $err .= "Good addresses that failed validation:\n";
         $err .= implode("\n", $goodfails);
     }
     if (count($badpasses) > 0) {
         if (!empty($err)) {
             $err .= "\n\n";
         }
         $err .= "Bad addresses that passed validation:\n";
         $err .= implode("\n", $badpasses);
     }
     $this->assertEmpty($err, $err);
     //For coverage
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', 'auto'));
     $this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'auto'));
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', 'pcre'));
     $this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre'));
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', 'pcre8'));
     $this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre8'));
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', 'php'));
     $this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'php'));
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', 'noregex'));
     $this->assertFalse(PHPMailer::validateAddress('bad', 'noregex'));
 }
Example #5
0
 /**
  * Send email.
  *
  * @since 1.0
  * @access public
  * @param $type string 
  * @param $init array 
  */
 public function mailer($type = 'mail', $init = array())
 {
     global $wpdb, $guiform;
     $subject = "";
     $MsgHTML = "";
     $sendTo = array_map('trim', explode(',', $init['to']));
     $sendCc = array_map('trim', explode(',', $init['cc']));
     $sendBcc = array_map('trim', explode(',', $init['bcc']));
     $sendReplyTo = array_map('trim', explode(',', $init['reply-to']));
     // Make sure the PHPMailer class has been instantiated
     // (Re)create it, if it's gone missing
     if (!is_object($phpmailer) || !is_a($phpmailer, 'PHPMailer')) {
         require_once ABSPATH . WPINC . '/class-phpmailer.php';
         require_once ABSPATH . WPINC . '/class-smtp.php';
         $phpmailer = new PHPMailer(true);
         $phpmailer->clearAllRecipients();
         $phpmailer->SMTPAuth = true;
     }
     if ($type == 'test-mail') {
         $data = $wpdb->get_row($wpdb->prepare("SELECT name, value FROM {$wpdb->guiform_options} WHERE id = %d", $this->_id));
         $sendTo = array($data->name);
         $row = unserialize($data->value);
         $row = array_map('trim', $row);
         $html = "<strong>" . __('Greetings!', GuiForm_Plugin::NAME) . "</strong><br /><br />";
         $html .= __("This is a test message.", GuiForm_Plugin::NAME) . "<br /><br />";
         $MsgHTML = self::emailTpl($html);
         $phpmailer->SetFrom("*****@*****.**", GuiForm_Plugin::PACKAGE);
         $phpmailer->Subject = __('Test Message', GuiForm_Plugin::NAME);
     } else {
         if ($type == 'activation-mail') {
             $data = $wpdb->get_row($wpdb->prepare("SELECT name, value FROM {$wpdb->guiform_options} WHERE id = %d", $this->_id));
             $row = unserialize($data->value);
             $row = array_map('trim', $row);
             $mv_code = md5(time());
             $row['key'] = $mv_code;
             $guiform->updateOption($data->name, $row, 'mail', $this->_id);
             $phpmailer->Subject = __("Email Verification", GuiForm_Plugin::NAME);
             $sendTo = array($data->name);
             $vlink = get_site_url() . "/?" . $guiform->getOption('permalink')->value['value'] . '=' . $this->_id . "&mv-code={$mv_code}";
             $html = "Hello " . $row['name'] . ",<br /><br />";
             $html .= __("To enable this email address from sending emails with your forms we must first verify by clicking the link below:", GuiForm_Plugin::NAME) . "<br /><br />";
             $html .= __("Verification Link: ", GuiForm_Plugin::NAME) . "<a target=\"_blank\" href=\"{$vlink}\">" . __("click here!", GuiForm_Plugin::NAME) . "</a><br /><br />";
             $MsgHTML = self::emailTpl($html);
             $phpmailer->SetFrom("*****@*****.**", "GuiForm");
         } else {
             if ($type == 'mail') {
                 $init['message'] = str_replace("\\r\\n", "<br />", $init['message']);
                 $init['message'] = stripcslashes($init['message']);
                 //Do not remove &nbsp and <br />.
                 $MsgHTML = $init['message'] . " &nbsp; <br />";
                 $phpmailer->SetFrom($init['from'], "");
                 $phpmailer->Subject = $init['subject'];
                 if (sizeof($init['attachment'])) {
                     foreach ($init['attachment'] as $file) {
                         $phpmailer->AddAttachment(self::getAttachmentPath($file['url']), $file['name']);
                     }
                 }
                 if (sizeof($sendReplyTo)) {
                     foreach ($sendReplyTo as $replyTo) {
                         if (is_email($replyTo)) {
                             $phpmailer->AddReplyTo($replyTo);
                         }
                     }
                 }
                 if (sizeof($sendCc)) {
                     foreach ($sendCc as $mailCc) {
                         if (is_email($mailCc)) {
                             $phpmailer->AddCC($mailCc);
                         }
                     }
                 }
                 if (sizeof($sendBcc)) {
                     foreach ($sendBcc as $mailBcc) {
                         if (is_email($mailBcc)) {
                             $phpmailer->AddCC($mailBcc);
                         }
                     }
                 }
             }
         }
     }
     $phpmailer->Body = html_entity_decode($MsgHTML);
     $phpmailer->AltBody = strip_tags($MsgHTML);
     $phpmailer->IsHTML(true);
     $phpmailer->CharSet = "UTF-8";
     foreach ($sendTo as $mailTo) {
         if ($phpmailer->validateAddress($mailTo)) {
             $phpmailer->AddAddress($mailTo);
         }
     }
     $smtpSettings = $guiform->getOption($this->form, false, 'smtp')->value;
     if ($smtpSettings->smtp_enable) {
         $row['protocol'] = 'smtp';
         $row['smtp_host'] = $smtpSettings->smtp_host;
         $row['smtp_port'] = $smtpSettings->smtp_port;
     }
     $phpmailer->Mailer = $row['protocol'];
     if ($row['protocol'] == 'smtp') {
         $phpmailer->IsSMTP();
         $phpmailer->SMTPSecure = $row['smtp_encryption'];
         $phpmailer->Host = $row['smtp_host'];
         $phpmailer->Port = $row['smtp_port'];
     }
     if (filter_var($row['smtp_auth'], FILTER_VALIDATE_BOOLEAN)) {
         $phpmailer->SMTPAuth = true;
         $phpmailer->Username = trim($row['smtp_username']);
         $phpmailer->Password = trim($row['smtp_password']);
     }
     if (!$phpmailer->send()) {
         die(__("Mailer Error: ", GuiForm_Plugin::NAME) . $phpmailer->ErrorInfo);
     } else {
         $phpmailer->clearAllRecipients();
         $phpmailer->clearAttachments();
         if ($type !== 'mail') {
             die(__("Message sent! Please check your email for message.", GuiForm_Plugin::NAME));
         }
     }
 }
Example #6
0
$example_code .= "\n\n\$results_messages = array();";
$mail = new PHPMailer(true);
//PHPMailer instance with exceptions enabled
$mail->CharSet = 'utf-8';
$mail->Debugoutput = $CFG['smtp_debugoutput'];
$example_code .= "\n\n\$mail = new PHPMailer(true);";
$example_code .= "\n\$mail->CharSet = 'utf-8';";
class phpmailerAppException extends phpmailerException
{
}
$example_code .= "\n\nclass phpmailerAppException extends phpmailerException {}";
$example_code .= "\n\ntry {";
try {
    if (isset($_POST["submit"]) && $_POST['submit'] == "Submit") {
        $to = $_POST['To_Email'];
        if (!PHPMailer::validateAddress($to)) {
            throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!");
        }
        $example_code .= "\n\$to = '{$_POST['To_Email']}';";
        $example_code .= "\nif(!PHPMailer::validateAddress(\$to)) {";
        $example_code .= "\n  throw new phpmailerAppException(\"Email address \" . " . "\$to . \" is invalid -- aborting!\");";
        $example_code .= "\n}";
        switch ($_POST['test_type']) {
            case 'smtp':
                $mail->isSMTP();
                // telling the class to use SMTP
                $mail->SMTPDebug = (int) $_POST['smtp_debug'];
                $mail->Host = $_POST['smtp_server'];
                // SMTP server
                $mail->Port = (int) $_POST['smtp_port'];
                // set the SMTP port
     foreach ($_POST as $valor) {
         if (stripos($valor, 'Content-Type:') !== FALSE) {
             echo "Ocurrió un error";
             exit;
         }
     }
     if ($_POST["ubicacion"] != "") {
         echo "Ocurrió un error";
         exit;
     }
     $datos_usuario = "Nombre: " . $nombre . "<br>";
     $datos_usuario .= "Email: " . $email . "<br>";
     $datos_usuario .= "Mensaje: " . $mensaje;
     require_once "inc/phpmailer/class.phpmailer.php";
     $mail = new PHPMailer();
     if ($mail->validateAddress($email)) {
         $mail->setFrom($email, $nombre);
         $mail->addAddress("*****@*****.**", "Nebaris Celulares");
         $mail->Subject = "Contacto desde el formulario - " . $nombre;
         $mail->msgHTML($datos_usuario);
         if ($mail->send()) {
             header("Location: contacto.php?estado=gracias");
             exit;
         } else {
             $mensaje_error = "No se pudo enviar el email.";
         }
     } else {
         $mensaje_error = "El email no es válido.";
     }
 } else {
     $mensaje_error = "El nombre, el email y el mensaje son obligatorios.";
Example #8
0
 /**
  * Test injecting a custom validator.
  */
 public function testCustomValidator()
 {
     //Inject a one-off custom validator
     $this->assertTrue(PHPMailer::validateAddress('*****@*****.**', function ($address) {
         return strpos($address, '@') !== false;
     }), 'Custom validator false negative');
     $this->assertFalse(PHPMailer::validateAddress('userexample.com', function ($address) {
         return strpos($address, '@') !== false;
     }), 'Custom validator false positive');
     //Set the default validator to an injected function
     PHPMailer::$validator = function ($address) {
         return '*****@*****.**' === $address;
     };
     $this->assertTrue($this->Mail->addAddress('*****@*****.**'), 'Custom default validator false negative');
     $this->assertFalse($this->Mail->addAddress('*****@*****.**'), 'Custom default validator false positive');
     //Set default validator to PHP built-in
     PHPMailer::$validator = 'php';
     $this->assertFalse($this->Mail->addAddress('first.last@example.123'), 'PHP validator not behaving as expected');
 }
Example #9
0
 public function sync_send_to()
 {
     $this->_get_mail_account();
     $title = $_REQUEST['name'];
     $body = $_REQUEST['content'];
     $to = $_REQUEST['wai1'];
     $cc = $_REQUEST['cc'];
     $bcc = $_REQUEST['bcc'];
     $this->_set_recent($to . $cc . $bcc);
     //header('Content-type:text/html;charset=utf-8');
     //vendor("Mail.class#send");
     import("@.ORG.Util.send");
     //从PHPMailer目录导入class.send.php类文件
     $mail = new PHPMailer(true);
     // the true param means it will throw exceptions on errors, which we need to catch
     $mail->IsSMTP();
     // telling the class to use SMTP
     try {
         $mail->Host = $this->_account['smtpsvr'];
         //"smtp.qq.com"; // SMTP server 部分邮箱不支持SMTP,QQ邮箱里要设置开启的
         $mail->SMTPDebug = false;
         // 改为2可以开启调试
         $mail->SMTPAuth = true;
         // enable SMTP authentication
         $mail->Port = 25;
         // set the SMTP port for the GMAIL server
         $mail->CharSet = "UTF-8";
         // 这里指定字符集!解决中文乱码问题
         $mail->Encoding = "base64";
         $mail->Username = $this->_account['mail_id'];
         // SMTP account username
         $mail->Password = $this->_account['mail_pwd'];
         // SMTP account password
         $mail->SetFrom($this->_account['email'], $this->_account['mail_name']);
         //发送者邮箱
         $mail->AddReplyTo($this->_account['email'], $this->_account['mail_name']);
         //回复到这个邮箱
         $arr_to = array_filter(explode(';', $to));
         foreach ($arr_to as $item) {
             //                dump($item);
             //                exit;
             if (strpos($item, "dept@group") !== false) {
                 $arr_tmp = array_filter(explode('|', $item));
                 $dept_id = str_replace("dept_", '', $arr_tmp[2]);
                 $mail_list = $this->get_mail_list_by_dept_id($dept_id);
                 foreach ($mail_list as $val) {
                     //                        dump($val);
                     //                        exit;
                     if (PHPMailer::validateAddress($item)) {
                         $mail->AddAddress($item, $val["emp_name"]);
                     }
                     // 收件人
                 }
             } else {
                 $arr_tmp = explode('|', $item);
                 if (PHPMailer::validateAddress($item)) {
                     $mail->AddAddress($item, $arr_tmp[0]);
                 }
                 // 收件人
             }
         }
         $arr_cc = array_filter(explode(';', $cc));
         foreach ($arr_to as $item) {
             if (strpos($item, "dept@group") !== false) {
                 $arr_tmp = array_filter(explode('|', $item));
                 $dept_id = str_replace("dept_", '', $arr_tmp[2]);
                 $mail_list = $this->get_mail_list_by_dept_id($dept_id);
                 foreach ($mail_list as $val) {
                     if (PHPMailer::validateAddress($val["email"])) {
                         $mail->AddAddress($val["email"], $val["emp_name"]);
                     }
                     // 收件人
                 }
             } else {
                 $arr_tmp = explode('|', $item);
                 if (PHPMailer::validateAddress($arr_tmp[1])) {
                     $mail->AddAddress($arr_tmp[1], $arr_tmp[0]);
                 }
                 // 收件人
             }
         }
         $arr_bcc = array_filter(explode(';', $bcc));
         foreach ($arr_bcc as $item) {
             if (strpos($item, "dept@group") !== false) {
                 $arr_tmp = array_filter(explode('|', $item));
                 $dept_id = str_replace("dept_", '', $arr_tmp[2]);
                 $mail_list = $this->get_mail_list_by_dept_id($dept_id);
                 foreach ($mail_list as $val) {
                     if (PHPMailer::validateAddress($val["email"])) {
                         $mail->AddAddress($val["email"], $val["emp_name"]);
                     }
                     // 收件人
                 }
             } else {
                 $tmp = explode('|', $item);
                 var_dump(PHPMailer::validateAddress($arr_tmp[1]));
                 if (PHPMailer::validateAddress($tmp[1])) {
                     $mail->AddAddress($tmp[1], $tmp[0]);
                 }
                 // 收件人
             }
         }
         $mail->Subject = "=?UTF-8?B?" . base64_encode($title) . "?=";
         //嵌入式图片处理
         if (preg_match('/\\/Data\\/files\\/\\d{6}\\/.{14}(jpg|gif|png)/', $body, $images)) {
             $i = 1;
             foreach ($images as $image) {
                 if (strlen($image) > 20) {
                     $cid = 'img' . $i++;
                     $name = $mail->AddEmbeddedImage(substr($image, 1), $cid);
                     $body = str_replace($image, "cid:{$cid}", $body);
                 }
             }
         }
         $mail->MsgHTML($body);
         $add_file = $_REQUEST['add_file'];
         if (!empty($add_file)) {
             $files = $this->_real_file($add_file);
             foreach ($files as $file) {
                 $mail->AddAttachment(get_save_path() . $file['savename'], $file['name']);
             }
         }
         //同步内部邮箱
         $flag = $this->_send();
         if (!$flag) {
             $this->error("内部错误");
         }
         if ($mail->Send()) {
             cookie('current_node', 105);
             $this->success("发送成功", U('mail/receiving'));
         } else {
             $this->error($mail->ErrorInfo);
         }
     } catch (phpmailerException $e) {
         echo $e->errorMessage();
         // $exception = $e -> errorMessage();
         // $this->error("发送失败!$exception");
         //Pretty error messages from PHPMailer
     } catch (Exception $e) {
         // echo "aaaaaa";
         echo $e->getMessage();
         //Boring error messages from anything else!
     }
 }
 public static function validateAddress($address, $patternselect = 'php')
 {
     return parent::validateAddress($address, $patternselect);
 }
Example #11
0
    public static function enviarEmail($para, $tipoEmail)
    {
        require_once 'PHPMailer/PHPMailerAutoload.php';
        $results_messages = array();
        $mail = new PHPMailer(true);
        $mail->CharSet = 'utf-8';
        ini_set('default_charset', 'UTF-8');
        $remetente = "*****@*****.**";
        $senha = 'S1st3m4d33m41llc4d';
        switch ($tipoEmail) {
            case 1:
                //Email Admin
                $assunto = 'Usuário Cadastrado';
                $texto = '<html>
							  <head>
							    <meta charset="utf-8">
							    <title></title>
							  </head>
							  <body>
							    <div class="box">
							      <div class="topo">
							        <div class="box-header with-border">
							          <h3 class="box-title">
							            Universidade Federal de Sergipe (UFS)<br>
							            Laboratório de Computação de Alto Desempenho (LCAD)
							          </h3>
							        </div>
							      </div>
							      <div>
							        <br>Um cadastro foi aprovado, seguem os dados:<br><br>
							        <b>Dados do Usuário</b> <br>
							        Nome: ' . $_SESSION['dados'][0] . '<br>
							        Email: ' . $_SESSION['dados'][1] . '<br>
							        Senha: ' . $_SESSION['dados'][2] . '<br>
							        Nucleo: ' . $_SESSION['dados'][3] . '<br>
							        Matricula: ' . $_SESSION['dados'][4] . '<br>
							        Nível: ' . $_SESSION['dados'][5] . '<br><br>
							        <b>Dados do Projeto</b><br>
							        Data Final: ' . $_SESSION['dados'][8] . '<br>
							        Título: ' . $_SESSION['dados'][6] . '<br>
							        Resumo: ' . $_SESSION['dados'][7] . '
							        Att,<br>
							        Administrador LCAD.<br><br>
							        <div class="main-footer" cellpadding="0" cellspacing="0">
						              Cidade Universitária “Prof. José Aloísio de Campos”<br>
						              Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
							        </div>
							      </div>
							    </div>
							  </body>
							</html>';
                break;
            case 2:
                //Email Cadastro Professor
                $assunto = 'Cadastro Aprovado';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá ' . $_SESSION['dados'][0] . ', o seu cadastro foi aprovado. <br><br>
			                      Acompanhe o andamento do projeto em: www.lcad.ufs.br, acessando o painel.<br><br>
			                      Muito obrigado,<br><br>
			                      Att,<br>
			                      Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 3:
                //Email Cadastro Aluno
                $assunto = 'Cadastro Aprovado';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                        <br>Olá ' . $_SESSION['dados'][0] . ' o seu cadastro foi aprovado. <br><br>
			                        Seguem os dados para acessar o sistema: <br>
			                        <b>Email: </b>' . $_SESSION['dados'][1] . '<br>
			                        <b>Senha: </b>' . $_SESSION['dados'][2] . '<br><br>
			                        Acompanhe o andamento do projeto em: www.lcad.ufs.br, acessando o painel.<br><br>
			                        Muito obrigado,<br><br>
			                        Att,<br>
			                        Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 4:
                //Email Projeto Aceito
                $assunto = 'Projeto Aprovado';
                $texto = '<html>
				            <head>
				              <meta charset="utf-8">
				              <title></title>
				            </head>
				            <body>
				              <div class="box">
				                <div class="topo">
				                  <div class="box-header with-border">
				                    <h3 class="box-title">
				                      Universidade Federal de Sergipe (UFS)<br>
				                      Laboratório de Computação de Alto Desempenho (LCAD)
				                    </h3>
				                  </div>
				                </div>
				                <div>
				                  <br>Olá ' . $_SESSION['dados'][0] . ', o seu projeto foi aprovado. <br><br>
				                  Acompanhe o andamento em: www.lcad.ufs.br, acessando o painel.<br><br>
				                  Muito obrigado,<br><br>
				                  Att,<br>
				                  Administrador LCAD.<br><br>
				                  <div class="main-footer" cellpadding="0" cellspacing="0">
				                      Cidade Universitária “Prof. José Aloísio de Campos”<br>
				                      Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
				                  </div>
				                </div>
				              </div>
				            </body>
				          </html>';
                break;
            case 5:
                //Email Projeto Recusado
                $assunto = 'Projeto Recusado';
                $texto = '<html>
				            <head>
				              <meta charset="utf-8">
				              <title></title>
				            </head>
				            <body>
				              <div class="box">
				                <div class="topo">
				                  <div class="box-header with-border">
				                    <h3 class="box-title">
				                      Universidade Federal de Sergipe (UFS)<br>
				                      Laboratório de Computação de Alto Desempenho (LCAD)
				                    </h3>
				                  </div>
				                </div>
				                <div>
				                  <br>Olá ' . $_SESSION['dados'][0] . ', o seu projeto foi recusado. <br><br>
				                  Segue a justificativa dada pelo líder:<br>
				                  ' . $_SESSION['justificativa'] . '<br><br>
				                  Acompanhe o andamento em: www.lcad.ufs.br, acessando o painel.<br><br>
				                  Muito obrigado,<br><br>
				                  Att,<br>
				                  Administrador LCAD.<br><br>
				                  <div class="main-footer" cellpadding="0" cellspacing="0">
				                      Cidade Universitária “Prof. José Aloísio de Campos”<br>
				                      Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
				                  </div>
				                </div>
				              </div>
				            </body>
				          </html>';
                unset($_SESSION['justificativa']);
                break;
            case 6:
                //Projeto Expirado
                $assunto = 'Projeto Expirado';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá ' . $_SESSION['dados'][0] . ', o seu projeto foi encerrado. <br><br>
				                  Segue a justificativa dada pelo líder:<br>
				                  ' . $_SESSION['justificativa'] . '<br><br>
				                  Acompanhe o andamento em: www.lcad.ufs.br, acessando o painel.<br><br>
			                      Muito obrigado,<br><br>
			                      Att,<br>
			                      Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 7:
                //Projeto Excluído
                $assunto = 'Projeto Excluído';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá ' . $_SESSION['dados'][0] . ', o seu projeto foi excluído. <br><br>
			                          Segue a justificativa dada pelo líder:<br>
			                          ' . $_SESSION['justificativa'] . '<br><br>
			                          Acompanhe o andamento em: www.lcad.ufs.br, acessando o painel.<br><br>
			                          Muito obrigado,<br><br>
			                          Att,<br>
			                          Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 8:
                //Projeto Renovado
                $assunto = 'Projeto Renovado';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá ' . $_SESSION['dados'][0] . ', o seu projeto foi renovado. <br><br>
			                          Segue a justificativa dada pelo líder:<br>
			                          ' . $_SESSION['justificativa'] . '<br><br>
			                          Acompanhe o andamento em: www.lcad.ufs.br, acessando o painel.<br><br>
			                          Muito obrigado,<br><br>
			                          Att,<br>
			                          Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 9:
                $assunto = 'Mensagem de um Usuário';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá, você recebeu uma nova mensagem:<br><br>
			                          <b>Nome: </b>' . $_SESSION['dados'][0] . '<br>
			                          <b>Email: </b>' . $_SESSION['dados'][1] . '<br>
			                          <b>Assunto: </b>' . $_SESSION['dados'][2] . '<br>
			                          <b>Mensagem: </b>' . $_SESSION['dados'][3] . '<br><br>
			                          Att,<br>
			                          Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 10:
                //Recuperação de Senha
                $assunto = 'Recuperação de Senha';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá, você solicitou uma nova senha: <br><br>
			                          <b>Senha: </b>' . $_SESSION['dados'][0] . '<br><br>
			                          A senha de acesso ao cluster será alterada também, em até 7 dias. Qualquer dúvida, entre em contato.
			                          Att,<br>
			                          Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
            case 11:
                //Recuperação de Senha
                $assunto = 'Recuperação de Senha';
                $texto = '<html>
			                <head>
			                  <meta charset="utf-8">
			                  <title></title>
			                </head>
			                <body>
			                  <div class="box">
			                    <div class="topo">
			                      <div class="box-header with-border">
			                        <h3 class="box-title">
			                          Universidade Federal de Sergipe (UFS)<br>
			                          Laboratório de Computação de Alto Desempenho (LCAD)
			                        </h3>
			                      </div>
			                    </div>
			                    <div>
			                      <br>Olá, um usuário alterou a senha: <br><br>
			                          <b>Email: </b>' . $_SESSION['dados'][1] . '<br>
			                          <b>Senha: </b>' . $_SESSION['dados'][2] . '<br><br>
			                          A senha de acesso ao cluster será alterada também, em até 7 dias. Qualquer dúvida, entre em contato.
			                          Att,<br>
			                          Administrador LCAD.<br><br>
			                      <div class="main-footer" cellpadding="0" cellspacing="0">
			                          Cidade Universitária “Prof. José Aloísio de Campos”<br>
			                          Av. Marechal Rondon, s/n – Jardim Rosa Elze – São Cristóvão-SE – CEP: 49100-000 <br>
			                      </div>
			                    </div>
			                  </div>
			                </body>
			              </html>';
                break;
        }
        // ATRIBUIÇÃO DE CONFIGURAÇÕES E ENVIO DE EMAIL COM TRATAMENTO DE ERRO
        try {
            // TESTE DA VALIDADE DO EMAIL FORNECIDO
            if (!PHPMailer::validateAddress($para)) {
                throw new phpmailerAppException("Email address " . $para . " is invalid -- aborting!");
            }
            // CONFIGURAÇÕES SMTP
            //$mail->SMTPDebug  = 2;
            $mail->isSMTP();
            $mail->Host = "smtp.gmail.com";
            $mail->Port = "587";
            $mail->SMTPSecure = "tls";
            $mail->SMTPAuth = true;
            // CONFIGURAÇÕES DA CONTA DE EMAIL REMETENTE
            $mail->Username = $remetente;
            $mail->Password = $senha;
            $mail->addReplyTo($remetente, "LCAD");
            $mail->setFrom($remetente, "LCAD");
            // CONFIGURAÇÕES DE ENVIO
            $mail->addAddress($para, "DESTINATARIO");
            $mail->Subject = $assunto;
            $body = $texto;
            $mail->WordWrap = 78;
            $mail->msgHTML($body, dirname(__FILE__), true);
            //Create message bodies and embed images
            // O ENVIO DO EMAIL É EFETIVADO
            try {
                $mail->send();
                //$results_messages[] = "Message has been sent using SMTP";
            } catch (phpmailerException $e) {
                //throw new phpmailerAppException('Unable to send to: ' . $to. ': '.$e->getMessage());
            }
        } catch (phpmailerAppException $e) {
            //$results_messages[] = $e->errorMessage();
        }
    }
Example #12
0
     if (!PHPMailer::validateAddress($d['email_empresa'])) {
         throw new phpmailerException("Email address " . $d['email_empresa'] . " is invalid -- aborting!");
     }
     if (!$correo->validateEmail($d['email_empresa'])) {
         throw new phpmailerException("Domain Email address " . $d['email_empresa'] . " is invalid -- aborting!");
     }
 } else {
     if (isset($d['correos'])) {
         $correos = explode(',', $d['correos']);
         foreach ($correos as $value) {
             echo 'ssss <br>';
             echo $value;
             echo '--------';
             $value = trim($value);
             $correo->addDestinatario($value, $value);
             if (!PHPMailer::validateAddress($value)) {
                 throw new phpmailerException("Email address " . $value . " is invalid -- aborting!");
             }
             if (!$correo->validateEmail($value)) {
                 throw new phpmailerException("Domain Email address " . $value . " is invalid -- aborting!");
             }
         }
     }
 }
 if (isset($d['requiere_acuse'])) {
     if ($d['requiere_acuse'] == 'si') {
         $correo->enableAcuseRecibo();
         $correo->setMensajeAcuse($d['mensaje_link_acuse']);
         $correo->setUrlAcuse($d['url_acuse']);
         $correo->setTokenAcuse($d['id_alarma']);
     }
Example #13
0
// storing all status output from the script to be shown to the user later
$results_messages = array();
// $example_code represents the "final code" that we're using, and will
// be shown to the user at the end.
$smsremarks = "Message Sent";
$mail = new PHPMailer(true);
//PHPMailer instance with exceptions enabled
$mail->CharSet = 'utf-8';
ini_set('default_charset', 'UTF-8');
$mail->Debugoutput = $CFG['smtp_debugoutput'];
class phpmailerAppException extends phpmailerException
{
}
try {
    if (isset($_POST["submit"]) && $_POST['submit'] == "Send") {
        if (!PHPMailer::validateAddress($to_email)) {
            throw new phpmailerAppException("Email address " . $to_email . " is invalid -- aborting!");
        }
        $mail->isSMTP();
        // telling the class to use SMTP
        $mail->SMTPDebug = (int) $smtp_debug;
        $mail->Host = $smtp_server;
        // SMTP server
        $mail->Port = (int) $smtp_port;
        // set the SMTP port
        if ($smtp_secure) {
            $mail->SMTPSecure = strtolower($smtp_secure);
        }
        $mail->SMTPAuth = $smtp_authenticate;
        $mail->Username = $authenticate_username;
        // SMTP account username