If email exists wordpress

Developer Resources

Determines whether the given email exists.

Contents

Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

Parameters

Return

int|false The user ID on success, false on failure.

More Information

This function will check whether or not a given email address ($email) has already been registered to a username, and returns that users ID (or false if none exists). See also username_exists.

This function is normally used when a user is registering, to ensure that the E-mail address the user is attempting to register with has not already been registered.

Source

Hooks

Filters whether the given email exists.

Uses

Retrieves user info by a given field.

Calls the callback functions that have been added to a filter hook.

Used By

Uses Description
get_user_by() wp-includes/pluggable.php
Used By

Updates a single user.

Sends a confirmation request email when a change of user email address is attempted.

Edit user settings based on contents of $_POST

Handles registering a new user.

Inserts a user into the database.

Sanitizes and validates data required for a user sign-up.

Changelog

Used By Description
WP_REST_Users_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
Changelog
Version Description
2.1.0 Introduced.

User Contributed Notes

Example
If the E-mail exists, echo the ID number to which the E-mail is registered. Otherwise, tell the viewer that it does not exist.

Bear in mind: this function is not defined in SHORTINIT

You must log in before being able to contribute a note or feedback.

Источник

email_exists() │ WP 2.1.0

Проверяет существует ли указанный email у зарегистрированных пользователей.

Хуки из функции

Возвращает

  • ID пользователя — если email уже существует.
  • false — если такого email еще нет в базе данных.

Использование

Примеры

#1 Проверка email пользователя при регистрации

Если email существует, то выведем ID пользователя, зарегистрированного с этим email. В противном случае, выведем надпись, что введенное мыло свободно и пользователь может быть зарегистрирован.

Добавить свой пример

Список изменений

Код email_exists() email exists WP 6.1

Cвязанные функции

Условные теги (все)

Остальное

Тимур, подскажите пожалуйста, можно ли как то проверить, при отправки комментария с сайта wp, адрес почты комментатора на существование вообще. Бывает просто люди пишут комментарий, а почту указывают левую. Или плагин типа DM Confirm Email, чтобы отправлял ссылку для подтверждения почты на эту же почту комментатора.

Невозможно проверить, существует или нет почтовый ящик, без участия владельца ящика (т.е. без подтверждения через письмо).

Если хочешь, чтобы только с существующими емейлами люди оставляли комментарии, то делай регистрацию на сайте и возможность комментирования только для зарегистрированных пользователей.

Источник

Developer Resources

Sends a confirmation request email when a change of user email address is attempted.

Contents

Source

Hooks

Filters the text of the email sent when a change of user email address is attempted.

Uses

Verifies that an email is valid.

Converts a number of HTML entities into their special characters.

Generates a random non-negative number.

Retrieves the current user object.

Sends an email, similar to PHP’s mail function.

Determines whether the given email exists.

Removes metadata matching criteria from a user.

Updates user meta field based on user ID.

Retrieves the translation of $text.

Checks and cleans a URL.

Retrieves the URL to the admin area for the current site.

Retrieves the URL for the current site where the front end is accessible.

Calls the callback functions that have been added to a filter hook.

Retrieves an option value based on an option name.

Initializes the error.

Changelog

Uses Description
is_email() wp-includes/formatting.php
Changelog
Version Description
4.9.0 This function was moved from wp-admin/includes/ms.php so it’s no longer Multisite specific.
3.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.

Источник

Developer Resources

Sends an email, similar to PHP’s mail function.

Contents

Description

A true return value does not automatically mean that the user received the email successfully. It just only means that the method used was able to process the request without any errors.

The default content type is text/plain which does not allow using HTML.
However, you can set the content type of the email by using the ‘wp_mail_content_type’ filter.

The default charset is based on the charset used on the blog. The charset can be set using the ‘wp_mail_charset’ filter.

Parameters

$attachments string | string[] Optional

Return

bool Whether the email was sent successfully.

More Information

Usage

Optional filters ‘wp_mail_from‘ and ‘wp_mail_from_name‘ are run on the sender email address and name. The return values are reassembled into a ‘from’ address like ‘”Example User” ‘ If only ‘wp_mail_from‘ returns a value, then just the email address will be used with no name.

The default content type is ‘text/plain’ which does not allow using HTML. You can set the content type of the email either by using the ‘wp_mail_content_type‘ filter ( see example below), or by including a header like “Content-type: text/html”. Be careful to reset ‘wp_mail_content_type’ back to ‘text/plain’ after you send your message, though, because failing to do so could lead to unexpected problems with e-mails from WP or plugins/themes.

The default charset is based on the charset used on the blog. The charset can be set using the ‘wp_mail_charset‘ filter.

Notes

  • A true return value does not automatically mean that the user received the email successfully.
  • For this function to work, the settings SMTP and smtp_port (default: 25) need to be set in your php.ini file.
  • The function is available after the hook ‘plugins_loaded’ .
  • The filenames in the $attachments attribute have to be filesystem paths.

Valid Address Formats

All email addresses supplied to wp_mail() as the $to parameter must comply with RFC 2822. Some valid examples:

  • user@example.com
  • user@example.com, anotheruser@example.com
  • User
  • User , Another User

The same applies to Cc: and Bcc: fields in $headers, but as noted in the next section, it’s better to push multiple addresses into an array instead of listing them on a single line. Either address format, with or without the user name, may be used.

Using $headers To Set “From:”, “Cc:” and “Bcc:” Parameters

To set the “From:” email address to something other than the WordPress default sender, or to add “Cc:” and/or “Bcc:” recipients, you must use the $headers argument.

$headers can be a string or an array, but it may be easiest to use in the array form. To use it, push a string onto the array, starting with “From:”, “Bcc:” or “Cc:” (note the use of the “:”), followed by a valid email address.

When you are using the array form, you do not need to supply line breaks ("\n" or "\r\n"). Although the function can handle multiple emails per line, it may simply be easier to push each email address separately onto the $headers array. The function will figure it out and will build the proper Mime header automagically. Just don’t forget that each string you push must have the header type as the first part of the string (“From:”, “Cc:” or “Bcc:”)

Source

Hooks

Fires after PHPMailer is initialized.

Filters whether to preempt sending an email.

Filters the wp_mail() arguments.

Filters the default wp_mail() charset.

Filters the wp_mail() content type.

Fires after a PHPMailer\PHPMailer\Exception is caught.

Filters the email address to send from.

Filters the name to associate with the “from” email address.

Fires after PHPMailer has successfully sent an email.

Uses

A wrapper for PHP’s parse_url() function that handles consistency in the return values across PHP versions.

Verifies that an email is valid.

Retrieves the home URL for the current network.

Calls the callback functions that have been added to an action hook, specifying arguments in an array.

Retrieves information about the current site.

Calls the callback functions that have been added to a filter hook.

Calls the callback functions that have been added to an action hook.

Initializes the error.

Used By

Uses Description
stripos() wp-includes/class-pop3.php
wp_parse_url() wp-includes/http.php
Used By

Notifies the Multisite network administrator that a new site was created.

Sends an email upon the completion or failure of a plugin or theme background update.

Sends the Recovery Mode email to the site admin email address.

Notifies the site administrator via email when a request is confirmed.

Notifies the user when their erasure request is fulfilled.

Send a confirmation request email to confirm an action.

Send an email to the user with a link to the personal data export file

Sends an email to the old site admin email address when the site admin email address changes.

Sends a confirmation request email when a change of network admin email address is attempted.

Sends an email to the old network admin email address when the network admin email address changes.

Handles sending a password retrieval email to a user.

Sends an email upon the completion or failure of a background core update.

Prepares and sends an email of a full log of background update results, useful for debugging and geekery.

Sends a confirmation request email when a change of site admin email address is attempted.

Sends a confirmation request email when a change of user email address is attempted.

Notifies the site admin that the installation of WordPress is complete.

Notifies the blog admin of a user changing password, normally via email.

Emails login credentials to a newly-registered user.

Notifies an author (and/or others) of a comment/trackback/pingback on a post.

Notifies the moderator of the site about a new comment that is awaiting approval.

Updates a user in the database.

Notifies a user that their account activation has been successful.

Notifies the network admin that a new site has been activated.

Notifies the network admin that a new user has been activated.

Notifies the site administrator that their site activation was successful.

Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active until the confirmation link is clicked.

Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site at the same time). The user account will not become active until the confirmation link is clicked.

Changelog

Used By Description
wpmu_new_site_admin_notification() wp-includes/ms-functions.php
WP_Automatic_Updater::send_plugin_theme_email() wp-admin/includes/class-wp-automatic-updater.php
WP_Recovery_Mode_Email_Service::send_recovery_mode_email() wp-includes/class-wp-recovery-mode-email-service.php
wp_privacy_send_personal_data_export_email() wp-admin/includes/privacy-tools.php
WP_Automatic_Updater::send_email() wp-admin/includes/class-wp-automatic-updater.php
WP_Automatic_Updater::send_debug_email() wp-admin/includes/class-wp-automatic-updater.php
Changelog
Version Description
5.5.0 is_email() is used for email validation, instead of PHPMailer’s default validator.
1.2.1 Introduced.

User Contributed Notes

To send HTML formatted mail, you also can specify the Content-Type HTTP header in the $headers parameter:

Example using the array form of $headers :

Feedback

Since WP started using hooks, you’re not going to have success setting the From header in wp_mail() . You should add filters to the hooks to add this header instead: add_filter( ‘wp_mail_from’, ‘wporg_wp_mail_from’ ); function wporg_wp_mail_from( $content_type) < return 'the.email@example.com'; >add_filter( ‘wp_mail_from_name’, ‘wporg_wp_mail_from_name’ ); function wporg_wp_mail_from_name( $name ) < return 'Your Name'; >— By Benji Kostenbader — 2 years ago

Here’s an example of a basic configuration for SMTP (so phpmailer will be used instead of php’s mail()):

Here’s an example of a basic error logging:

Then use wp_mail() to send your mail.

If you’re using it for sending a form and your form’s action is the page’s permalink, you can do some basic checking for $_POST lenght/count to see if the page comes from a form submission.

NOTE: if you are using MAMP PRO to test from your local server, you should:

– go to the Postfix panel
– write your current virtual server as the ‘domain of outgoing email’
– activate ‘use a smart host for routing’
– write your provider’s smtp server (the same you are using in your mail client config)
– Eventually add authentication (then you should also setup the credentials in the phpmailer_init action)

Feedback

This is a great example, just one note: PHPMailer has moved. The function call needs to be modified.

function mailer_config(\PHPMailer\PHPMailer\PHPMailer $mail)< — By Martin Schneider — 1 year ago

Having spent nearly a day banging my head against this one, I would strongly recommend that the doc for wp_mail() include the tip that many servers will require that a mail user account be created with the email address of wordpress@domain.com before this function will work. I would have NEVER figured that one out without many hours of google searches.

Feedback

Fellow head-banger here. This is actually an insane requirement in those cases when the email server is (physically) different from the web server hosting WordPress; site admins might not have any possibility to add such an address. I would classify this as a bug, but, taking into account that your message is 5 years old at the time of writing this feedback, one may safely assume that this is intended behaviour (why?). Also, note that while it’s possible to use alternative email facilities to avoid going through PHP’s mail() function, WordPress will still require that wordpress@domain.com to be around (and additionally, in some circumstances, webmaster@domain.com . So, if you’re able to generate those two mailboxes (or aliases), do that — it will save you from trouble in the future — unless, that is, someone at the core WordPress development team decides to change this behaviour (as they ought to have done years ago…) — By Gwyneth Llewelyn — 12 months ago

Combining Content-Type(HTML) and From (Site name and “from” email)

If you need to set the Reply-To address, note that the syntax which PHPMailer needs is pretty specific. The email address must be enclosed within <> characters. It’s also advisable to set the “reply to” name.

Switch to HTML formatted email (using the wp_mail_content_type filter):

Basic usage example:

Add attachment and From header:

Sending to multiple recipients:

It’s important to know that this function might fail if you specify an empty body, even if using a SMTP.

To send e-mail to admin:

Feedback

I think it should be wp_mail( $to, $subject, $message, $headers, array( ” ) ); instead — By simongcc — 3 years ago

As of 4.6 header from can’t be a post variable, need to be set before otherwise your site will show php error “Fatal error: Uncaught exception ‘phpmailerException’ with message ‘Invalid address: (setFrom)”

This is due to ‘from email’ being set as variable and is not yet being passed by form submit.

Fix by predefining a variable for both $name and $email that will be overwritten after submit(ex.1), or set hardcoded(ex.2).
ex.1

Emails will not send correctly if the $to parameter is over 500 characters. You will still get a true response from wp_mail() however.

You must log in before being able to contribute a note or feedback.

Источник

Читайте также:  0x1900101 0x20017 как исправить
Поделиться с друзьями
КомпСовет
Adblock
detector