本文整理汇总了PHP中valid_email_address函数的典型用法代码示例。如果您正苦于以下问题:PHP valid_email_address函数的具体用法?PHP valid_email_address怎么用?PHP valid_email_address使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了valid_email_address函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateForm
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
$form_state->set('notify_emails', []);
if (!$form_state->isValueEmpty('update_notify_emails')) {
$valid = array();
$invalid = array();
foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
if (valid_email_address($email)) {
$valid[] = $email;
} else {
$invalid[] = $email;
}
}
}
if (empty($invalid)) {
$form_state->set('notify_emails', $valid);
} elseif (count($invalid) == 1) {
$form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
} else {
$form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
}
}
parent::validateForm($form, $form_state);
}
示例2: validateForm
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$form_state)
{
$form_state['notify_emails'] = array();
if (!empty($form_state['values']['update_notify_emails'])) {
$valid = array();
$invalid = array();
foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
$email = trim($email);
if (!empty($email)) {
if (valid_email_address($email)) {
$valid[] = $email;
} else {
$invalid[] = $email;
}
}
}
if (empty($invalid)) {
$form_state['notify_emails'] = $valid;
} elseif (count($invalid) == 1) {
$this->setFormError('update_notify_emails', $form_state, $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
} else {
$this->setFormError('update_notify_emails', $form_state, $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
}
}
parent::validateForm($form, $form_state);
}
示例3: validateEmail
/**
* Form element validation handler for #type 'email'.
*
* Note that #maxlength and #required is validated by _form_validate() already.
*/
public static function validateEmail(&$element, FormStateInterface $form_state, &$complete_form)
{
$value = trim($element['#value']);
$form_state->setValueForElement($element, $value);
if ($value !== '' && !valid_email_address($value)) {
$form_state->setError($element, t('The email address %mail is not valid.', array('%mail' => $value)));
}
}
示例4: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$added = array();
$invalid = array();
$unsubscribed = array();
$checked_newsletters = array_keys(array_filter($form_state->getValue('newsletters')));
$langcode = $form_state->getValue('language');
$emails = preg_split("/[\\s,]+/", $form_state->getValue('emails'));
foreach ($emails as $email) {
$email = trim($email);
if ($email == '') {
continue;
}
if (valid_email_address($email)) {
$subscriber = simplenews_subscriber_load_by_mail($email);
/** @var \Drupal\simplenews\Subscription\SubscriptionManagerInterface $subscription_manager */
$subscription_manager = \Drupal::service('simplenews.subscription_manager');
foreach (simplenews_newsletter_load_multiple($checked_newsletters) as $newsletter) {
// If there is a valid subscriber, check if there is a subscription for
// the current newsletter and if this subscription has the status
// unsubscribed.
$is_unsubscribed = $subscriber ? $subscriber->isUnsubscribed($newsletter->id()) : FALSE;
if (!$is_unsubscribed || $form_state->getValue('resubscribe') == TRUE) {
$subscription_manager->subscribe($email, $newsletter->id(), FALSE, 'mass subscribe', $langcode);
$added[] = $email;
} else {
$unsubscribed[$newsletter->label()][] = $email;
}
}
} else {
$invalid[] = $email;
}
}
if ($added) {
$added = implode(", ", $added);
drupal_set_message(t('The following addresses were added or updated: %added.', array('%added' => $added)));
$list_names = array();
foreach (simplenews_newsletter_load_multiple($checked_newsletters) as $newsletter) {
$list_names[] = $newsletter->label();
}
drupal_set_message(t('The addresses were subscribed to the following newsletters: %newsletters.', array('%newsletters' => implode(', ', $list_names))));
} else {
drupal_set_message(t('No addresses were added.'));
}
if ($invalid) {
$invalid = implode(", ", $invalid);
drupal_set_message(t('The following addresses were invalid: %invalid.', array('%invalid' => $invalid)), 'error');
}
foreach ($unsubscribed as $name => $subscribers) {
$subscribers = implode(", ", $subscribers);
drupal_set_message(t('The following addresses were skipped because they have previously unsubscribed from %name: %unsubscribed.', array('%name' => $name, '%unsubscribed' => $subscribers)), 'warning');
}
if (!empty($unsubscribed)) {
drupal_set_message(t("If you would like to resubscribe them, use the 'Force resubscription' option."), 'warning');
}
// Return to the parent page.
$form_state->setRedirect('view.simplenews_subscribers.page_1');
}
示例5: os_poker_admin_form_validate
function os_poker_admin_form_validate($from, &$form_state)
{
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
if ($op != t('Reset to defaults')) {
if (!valid_email_address($form_state['values']['os_poker_abuse_mail_to'])) {
form_set_error('os_poker_abuse_mail_to', t('The e-mail address you specified is not valid.'));
}
}
}
示例6: entityValidate
/**
* Validates a user account.
*/
public function entityValidate($account)
{
if (empty($account->name->value) || empty($account->mail->value) || !valid_email_address($account->mail->value)) {
throw new ValidationException('User name missing or email not valid.');
}
if ($this->configuration['defuse_mail']) {
$account->mail = $account->mail->value . '_test';
}
// Remove pass from $account if the password is unchanged.
if (isset($account->feeds_original_pass) && $account->pass == $account->feeds_original_pass) {
unset($account->pass);
}
}
示例7: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// Validate and each email recipient.
$recipients = explode(',', $form_state['values']['recipients']);
foreach ($recipients as &$recipient) {
$recipient = trim($recipient);
if (!valid_email_address($recipient)) {
$form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
}
}
$form_state['values']['recipients'] = $recipients;
}
示例8: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
$values = $form_state->getValues();
if ($values['smtp_on'] == 1 && $values['smtp_host'] == '') {
$form_state->setErrorByName('smtp_host', $this->t('You must enter an SMTP server address.'));
}
if ($values['smtp_on'] == 1 && $values['smtp_port'] == '') {
$form_state->setErrorByName('smtp_port', $this->t('You must enter an SMTP port number.'));
}
if ($values['smtp_from'] && !valid_email_address($values['smtp_from'])) {
$form_state->setErrorByName('smtp_from', $this->t('The provided from e-mail address is not valid.'));
}
if ($values['smtp_test_address'] && !valid_email_address($values['smtp_test_address'])) {
$form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
}
// If username is set empty, we must set both username/password empty as well.
if (empty($values['smtp_username'])) {
$values['smtp_password'] = '';
} elseif (empty($values['smtp_password'])) {
$form_state->unsetValue('smtp_password');
}
}
示例9: mailer
/**
* Mailer.
*/
public function mailer(Request $request)
{
$content = $request->getContent();
if (empty($content)) {
return new JsonResponse(['status' => 'error']);
}
$params = Json::decode($content);
$email = $params['email'];
$result = $params['selection'];
$progress = $params['progress'];
// Handle errors.
if (!valid_email_address($email) || strlen($result) < 2) {
return new JsonResponse(['status' => 'error']);
}
// Prepare email.
$to = [$email];
$view = views_embed_view('answer', 'rest_export_1', $result);
$content = \Drupal::service('renderer')->render($view);
$nodes = Json::decode($content);
// Get the hidden fields
$view = views_embed_view('hideanswers', 'rest_export_1', $result);
$content = \Drupal::service('renderer')->render($view);
$hidden = Json::decode($content);
$hidden = array_map(function ($item) {
return $item['nid'];
}, $hidden);
$view = views_embed_view('disclaimer', 'rest_export_1', $result);
$content = \Drupal::service('renderer')->render($view);
$disclaimer = Json::decode($content);
$view = views_embed_view('intro_email', 'rest_export_1', $result);
$content = \Drupal::service('renderer')->render($view);
$intro = Json::decode($content);
$result = \Drupal::service('plugin.manager.mail')->mail('angapp', 'results', implode(', ', $to), \Drupal::currentUser()->getPreferredLangcode(), ['progress' => $progress, 'intro' => $intro, 'disclaimer' => $disclaimer, 'nodes' => $nodes, 'hidden' => $hidden]);
if ($result['result'] === TRUE) {
return new JsonResponse(['status' => 'ok']);
} else {
return new JsonResponse(['status' => 'error']);
}
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$removed = array();
$invalid = array();
$checked_lists = array_keys(array_filter($form_state->getValue('newsletters')));
/** @var \Drupal\simplenews\Subscription\SubscriptionManagerInterface $subscription_manager */
$subscription_manager = \Drupal::service('simplenews.subscription_manager');
$emails = preg_split("/[\\s,]+/", $form_state->getValue('emails'));
foreach ($emails as $email) {
$email = trim($email);
if (valid_email_address($email)) {
foreach ($checked_lists as $newsletter_id) {
$subscription_manager->unsubscribe($email, $newsletter_id, FALSE, 'mass unsubscribe');
$removed[] = $email;
}
} else {
$invalid[] = $email;
}
}
if ($removed) {
$removed = implode(", ", $removed);
drupal_set_message(t('The following addresses were unsubscribed: %removed.', array('%removed' => $removed)));
$newsletters = simplenews_newsletter_get_all();
$list_names = array();
foreach ($checked_lists as $newsletter_id) {
$list_names[] = $newsletters[$newsletter_id]->label();
}
drupal_set_message(t('The addresses were unsubscribed from the following newsletters: %newsletters.', array('%newsletters' => implode(', ', $list_names))));
} else {
drupal_set_message(t('No addresses were removed.'));
}
if ($invalid) {
$invalid = implode(", ", $invalid);
drupal_set_message(t('The following addresses were invalid: %invalid.', array('%invalid' => $invalid)), 'error');
}
// Return to the parent page.
$form_state->setRedirect('view.simplenews_subscribers.page_1');
}
示例11: checkValue
public function checkValue($value, $type) {
$min_length = 0;
$max_length = 0;
$regexp = false;
$optional = false;
if (is_array($type)) {
$min_length = isset($type['min_length']) ? (int) $type['min_length'] : 0;
$max_length = isset($type['max_length']) ? (int) $type['max_length'] : 0;
$regexp = isset($type['regexp']) ? $type['regexp'] : false;
$optional = isset($type['*']) ? true : false;
$type = $type['type'];
}
switch ($type) {
case 'email':
if (!valid_email_address($value))
return false;
break;
case 'string':
if (!$value && $optional)
return '';
if (!$value)
return false;
if ($min_length)
if (mb_strlen(trim($value), 'UTF-8') < $min_length)
return false;
if ($max_length)
if (mb_strlen(trim($value), 'UTF-8') > $max_length)
return false;
if ($regexp)
if (!preg_match($regexp, $value))
return false;
break;
case 'int':
if ($value == null) {
if ($optional)
return false;
}
if (!is_numeric($value)) {
$value = (int) $value;
}
break;
case '':
break;
}
return $value;
}
示例12: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
if (!valid_email_address($form_state->getValue('email'))) {
$form_state->setErrorByName('email', t('That e-mail address is not valid.'));
}
}
示例13: _email_verify_check
/**
* Primary function for validating email addresses.
*
* @param string $mail
* An email address to check, such as drupal@drupal.org.
*
* @return
* Empty if address is valid, a text error string if it's invalid.
*/
function _email_verify_check($mail)
{
if (!valid_email_address($mail)) {
// The address is syntactically incorrect.
// The problem will be caught by the 'user' module anyway, so we avoid
// duplicating the error reporting here, just return.
return;
}
// Only add include if we are running Windows
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
include_once dirname(__FILE__) . '/windows_compat.inc';
}
$host = substr(strchr($mail, '@'), 1);
// If the domain is not cached, perform tests
if (!_email_verify_checkdb($host)) {
// Let's see if we can find anything about this host in the DNS
if (!checkdnsrr($host, 'ANY')) {
return t('Email host %host invalid, please retry.', array('%host' => "{$host}"));
}
if ($whitelist = variable_get('email_verify_whitelist', FALSE)) {
$whitelist = explode("\n", $whitelist);
if (in_array($host, $whitelist)) {
return;
}
}
// What SMTP servers should we contact?
$mx_hosts = array();
if (!getmxrr($host, $mx_hosts)) {
// When there is no MX record, the host itself should be used
$mx_hosts[] = $host;
}
// Try to connect to one SMTP server
foreach ($mx_hosts as $smtp) {
$connect = @fsockopen($smtp, 25, $errno, $errstr, 15);
if (!$connect) {
continue;
}
if (ereg("^220", $out = fgets($connect, 1024))) {
// OK, we have a SMTP connection
break;
} else {
// The SMTP server probably does not like us
// (dynamic/residential IP for aol.com for instance)
// Be on the safe side and accept the address, at least it has a valid
// domain part...
watchdog('email_verify', "Could not verify email address at host {$host}: {$out} for {$mail}");
return;
}
}
if (!$connect) {
return t('Email host %host is invalid, please contact us for clarification.', array('%host' => "{$host}"));
}
$from = variable_get('site_mail', ini_get('sendmail_from'));
// Extract the <...> part if there is one
if (preg_match('/\\<(.*)\\>/', $from, $match) > 0) {
$from = $match[1];
}
$localhost = $_SERVER["HTTP_HOST"];
if (!$localhost) {
// Happens with HTTP/1.0
// should be good enough for RFC compliant SMTP servers
$localhost = 'localhost';
}
fputs($connect, "HELO {$localhost}\r\n");
$out = fgets($connect, 1024);
fputs($connect, "MAIL FROM: <{$from}>\r\n");
$from = fgets($connect, 1024);
fputs($connect, "RCPT TO: <{$mail}>\r\n");
$to = fgets($connect, 1024);
fputs($connect, "QUIT\r\n");
fclose($connect);
if (!ereg("^250", $from)) {
// Again, something went wrong before we could really test the address,
// be on the safe side and accept it.
watchdog('email_verify', "Could not verify email address at host {$host}: {$from}");
return;
}
if (ereg("(Client host|Helo command) rejected", $to) || ereg("^4", $to) && !ereg("^450", $to)) {
// In those cases, accept the email, but log a warning
watchdog('email_verify', "Could not verify email address at host {$host}: {$to}");
return;
}
if (!ereg("^250", $to)) {
watchdog('email_verify', "Rejected email address: {$mail}. Reason: {$to}");
return t('%mail is invalid, please contact us for clarification.', array('%mail' => "{$mail}"));
}
// If the previous checks pass, save the valid domain to the DB table.
_email_verify_updatedb($host);
}
// Everything OK
return;
//.........这里部分代码省略.........
示例14: libya_quick_subscribe_form_validate
function libya_quick_subscribe_form_validate($form, &$form_state)
{
$mail = $form_state['values']['mail'];
$obj = subscriptionData('read', $mail);
if (gettype($obj) == 'object' && $obj->mail) {
$resend = '';
if ($obj->confirm == 0) {
$resend = '<a class="my-btn" href="#" data-mail="' . $obj->mail . '" data-key="' . $obj->code . '" id="resend">resend confirmation mail</a>';
}
form_set_error('subscribe][mail', t('This email is already subscribed. ') . $resend);
}
if (!valid_email_address($mail)) {
form_set_error('mail', t('Email address did not validate: please check'));
}
}
示例15: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
if ($values['smtp_on'] == 1 && $values['smtp_host'] == '') {
$form_state->setErrorByName('smtp_host', $this->t('You must enter an SMTP server address.'));
}
if ($values['smtp_on'] == 1 && $values['smtp_port'] == '') {
$form_state->setErrorByName('smtp_port', $this->t('You must enter an SMTP port number.'));
}
if ($values['smtp_from'] && !valid_email_address($values['smtp_from'])) {
$form_state->setErrorByName('smtp_from', $this->t('The provided from e-mail address is not valid.'));
}
if ($values['smtp_test_address'] && !valid_email_address($values['smtp_test_address'])) {
$form_state->setErrorByName('smtp_test_address', $this->t('The provided test e-mail address is not valid.'));
}
// If username is set empty, we must set both username/password empty as well.
if (empty($values['smtp_username'])) {
$values['smtp_password'] = '';
}
// A little hack. When form is presented, the password is not shown (Drupal way of doing).
// So, if user submits the form without changing the password, we must prevent it from being reset.
elseif (empty($values['smtp_password'])) {
$form_state->unsetValue('smtp_password');
}
}