本文整理汇总了PHP中PHPMailer::validateAddress方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPMailer::validateAddress方法的具体用法?PHP PHPMailer::validateAddress怎么用?PHP PHPMailer::validateAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPMailer
的用法示例。
在下文中一共展示了PHPMailer::validateAddress方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verify_emails
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);
}
示例2: validateAddress
/**
* @inheritdoc
*/
public static function validateAddress($address, $patternselect = null)
{
if ($patternselect === null) {
$patternselect = self::$patternSelect;
}
return parent::validateAddress($address, $patternselect);
}
示例3: sendMail
/**
* 发送邮件
* @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;
}
}
示例4: testValidate
/**
* 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@iana.org', 'first.last@iana.org', '1234567890123456789012345678901234567890123456789012345678901234@iana.org', '"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@x23456789012345678901234567890123456789012345678901234567890123.iana.org', 'first.last@3com.com', 'first.last@123.iana.org', '"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', 'user+mailbox@iana.org', 'customer/department=shipping@iana.org', '$A12345@iana.org', '!def!xyz%abc@iana.org', '_somename@iana.org', 'dclo@us.ibm.com', 'peter.piper@iana.org', '"Doug \\"Ace\\" L."@iana.org', 'test@iana.org', 'TEST@iana.org', '1234567890@iana.org', 'test+test@iana.org', 'test-test@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@test"@iana.org', 'test@123.123.123.x123', 'test@123.123.123.123', 'test@[123.123.123.123]', 'test@example.iana.org', 'test@example.example.iana.org', '"test\\test"@iana.org', 'test@example', '"test\\blah"@iana.org', '"test\\blah"@iana.org', '"test\\"blah"@iana.org', 'customer/department@iana.org', '_Yosemite.Sam@iana.org', '~@iana.org', '"Austin@Powers"@iana.org', 'Ima.Fool@iana.org', '"Ima.Fool"@iana.org', '"Ima Fool"@iana.org', '"first"."last"@iana.org', '"first".middle."last"@iana.org', '"first".last@iana.org', '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', 'name.lastname@domain.com', 'a@b', 'a@bar.com', 'aaa@[123.123.123.123]', 'a@bar', 'a-b@bar.com', '+@b.c', '+@b.com', 'a@b.co-foo.uk', '"hello my name is"@stutter.com', '"Test \\"Fail\\" Ing"@iana.org', 'valid@about.museum', 'shaitan@my-domain.thisisminekthx', '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]', 'test@test.com', 'test@xn--example.com', 'test@example.com');
$invalidaddresses = array('first.last@sub.do,com', 'first\\@last@iana.org', '123456789012345678901234567890123456789012345678901234567890' . '@12345678901234567890123456789012345678901234 [...]', 'first.last', '12345678901234567890123456789012345678901234567890123456789012345@iana.org', '.first.last@iana.org', 'first.last.@iana.org', 'first..last@iana.org', '"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]', 'first.last@-xample.com', 'first.last@exampl-.com', 'first.last@x234567890123456789012345678901234567890123456789012345678901234.iana.org', '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@', '"qu@iana.org', 'ote"@iana.org', '.dot@iana.org', 'dot.@iana.org', 'two..dot@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.@iana.org', 'test..test@iana.org', '.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', '.wooly@iana.org', 'wo..oly@iana.org', 'pootietang.@iana.org', '.@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.', 'a@-b.com', 'a@b-.com', '-@..com', '-@a..com', 'invalid@about.museum-', 'test@...........com', '"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('test@example.com', 'auto'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'auto'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'pcre'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'pcre8'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'pcre8'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'php'));
$this->assertFalse(PHPMailer::validateAddress('test@example.com.', 'php'));
$this->assertTrue(PHPMailer::validateAddress('test@example.com', 'noregex'));
$this->assertFalse(PHPMailer::validateAddress('bad', 'noregex'));
}
示例5: mailer
/**
* 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("noreply@guiform.com", 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("noreply@guiform.com", "GuiForm");
} else {
if ($type == 'mail') {
$init['message'] = str_replace("\\r\\n", "<br />", $init['message']);
$init['message'] = stripcslashes($init['message']);
//Do not remove   and <br />.
$MsgHTML = $init['message'] . " <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) {
//.........这里部分代码省略.........
示例6: array
$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
示例7: foreach
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("contacto@nebariscelulares.com", "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.";
示例8: testCustomValidator
/**
* Test injecting a custom validator.
*/
public function testCustomValidator()
{
//Inject a one-off custom validator
$this->assertTrue(PHPMailer::validateAddress('user@example.com', 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 'user@example.com' === $address;
};
$this->assertTrue($this->Mail->addAddress('user@example.com'), 'Custom default validator false negative');
$this->assertFalse($this->Mail->addAddress('bananas@example.com'), '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');
}
示例9: sync_send_to
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]);
}
// 收件人
//.........这里部分代码省略.........
示例10: validateAddress
public static function validateAddress($address, $patternselect = 'php')
{
return parent::validateAddress($address, $patternselect);
}
示例11: enviarEmail
//.........这里部分代码省略.........
<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();
}
}
示例12: phpmailerException
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']);
}
示例13: array
// 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