php-wordpressHow to send an email using PHP in WordPress?
Sending an email using PHP in WordPress is a simple process. The following example code block can be used to send an email using PHP in WordPress:
<?php
$to = '[email protected]';
$subject = 'Test Email';
$body = 'This is a test email sent using PHP in WordPress.';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
?>
The output of the example code is a successful email sent to the specified address.
Code explanation
$to
: This is the email address of the recipient.$subject
: This is the subject of the email.$body
: This is the body of the email.$headers
: This is an array of headers to be sent with the email.wp_mail()
: This is the WordPress function used to send the email.
Helpful links
More of Php Wordpress
- How to disable PHP warnings in WordPress?
- How to use get_header in WordPress using PHP?
- How to increase the upload limit in WordPress using PHP?
- How to get the current URL in WordPress using PHP?
- How to add a shortcode in WordPress?
- How to create a snippet in WordPress using PHP?
- How to run an SQL query in WordPress using PHP?
- How to use the WordPress REST API with PHP?
- How to redirect to another page in WordPress using PHP?
See more codes...