How to send an email in wordpress without plugins?

Member

by shyann , in category: PHP CMS , 20 days ago

How to send an email in wordpress without plugins?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 19 days ago

@shyann 

To send an email in WordPress without using plugins, you can use the native PHP function wp_mail() which is available in WordPress. Here are the steps to send an email:

  1. Start by locating the PHP file or template where you want to add the email sending functionality. This can be the theme's functions.php file or a custom template file.
  2. Open the file you located in a code editor and add the following code snippet at the desired location:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php
$to = '[email protected]';
$subject = 'Email Subject';
$body = 'Email Body';

$headers = array('Content-Type: text/html; charset=UTF-8');

// Send email
wp_mail( $to, $subject, $body, $headers );
?>


Replace [email protected] with the email address where you want to send the email. Adjust the subject and body of the email as per your requirements.

  1. Save the file and upload it to your WordPress installation.
  2. When this code is executed, an email will be sent using the WordPress built-in email functionality. The wp_mail() function automatically uses the email settings configured in your WordPress installation.


Note: Ensure that your WordPress installation has proper email configuration, such as SMTP settings, to ensure successful email delivery.