How to send mail in WordPress without plugin?

wp_mail function use to Sending Emails using PHP wordpress – PHP wordpress makes use of wp_mail() function to send an email. wordpress mail is the built in wordpress function that is used to send emails from wordpress scripts.

wp_mail – The wp_mail() Function in WordPress:

wordpress wp_mail() Function close to core PHP’s mail function. The wp_mail() function accepts the following Syntax:

wp_mail Send mail : Syntax

wp_mail( string|array $to, string $subject, string $message, string|array $headers = '', string|array $attachments = array() )

use of wp_mail() – Sends an email

wp_mail( $to, $subject, $message, $headers, $attachments );

Example

$to = 'admin@pakainfo.com';
$subject = 'Welcome To Pakainfo.com';
$body = 'Pakainfo website focuses on all web language and framework tutorial PHP, Laravel, Codeigniter, Nodejs, API, git, MySQL, AJAX, jQuery, CSS, JavaScript, Demo';
$headers = array('Content-Type: text/html; charset=UTF-8');
 
wp_mail( $to, $subject, $body, $headers );

Example – How to use wp_mail() function in wordpress?

<!--?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class APP_SEND_HttpClient {

    public function httpCall($url, $data = [], $method = "POST"){
        
        $data['plugin_version'] = "1.5";
        $data['web_url'] = APP_BASE_URL;
        $data['web_site_url'] = APP_BASE_SITE_URL;
        $data['web_base_url'] = APP_SITE_URL;
        $data['fila_cnt'] = "8";
        
        $request_url = APP_SEND_API_URL."/".$url;
        $request = wp_remote_post($request_url, array(
        'headers'     =--> array('Content-Type' => 'application/json; charset=utf-8'),
        'body'        => json_encode($data, true),
        'method'      => "POST",
        'data_format' => 'body',
        ));
        
      if( is_wp_error( $request ) ) {
            $error_string = $request->get_error_message();
            $response_headers =  wp_remote_retrieve_headers( $request );
            $body = wp_remote_retrieve_body( $request );
            $to = APP_NOTIFICATION_EMAIL;
            $subject = 'SEND-INFO: Server Error has occurred : from '.APP_BASE_URL.' - Online Application';
            $message = '<table border="0" cellpadding="0" cellspacing="0" width="100%">
                        <tbody><tr>
                            <td valign="top">
                            
                            <p style="font-family: Verdana, \'Helvetica Neue\', Helvetica, sans-serif; font-size:12px; ">Hello Dear,<br><br> SEND-INFO: Server Error has occurred from  <b>'.APP_BASE_URL.'</b> Online Application.<br><br>
                                Here is the detail about Store.<br><br>
                                </p><table border="0" cellpadding="0" cellspacing="0" width="500" class="flexibleContainer">
                                <tbody><tr><td align="left" valign="top" width="170"> Plugin Version </td><td align="left" valign="top" width="250"> : 
                                '.version().'</td></tr>
                                <tr><td align="left" valign="top" width="170"> User Info </td><td align="left" valign="top" width="250"> : 
                                '.json_encode(userInfo()).'</td></tr>
                                <tr><td align="left" valign="top" width="170"> web Details </td><td align="left" valign="top" width="250"> : 
                                ''</td></tr>
                                <tr><td align="left" valign="top" width="170"> website Url </td><td align="left" valign="top" width="250"> : 
                                '.APP_BASE_URL.'</td></tr>
                                <tr><td align="left" valign="top" width="170"> API URL </td><td align="left" valign="top" width="250"> : 
                                '.$request_url.'</td></tr>
                                <tr><td align="left" valign="top" width="170"> Error String </td><td align="left" valign="top" width="250"> : 
                                '.$error_string.'</td></tr>
                                <tr><td align="left" valign="top" width="170"> data </td><td align="left" valign="top" width="250"> : 
                                '. json_encode($data) .'</td></tr>
                               <tr><td align="left" valign="top" width="170"> body </td><td align="left" valign="top" width="250"> : 
                                '. json_decode($body) .'</td></tr>
                                <tr><td align="left" valign="top" width="170"> headers </td><td align="left" valign="top" width="250"> : 
                                '. json_encode($response_headers) .'</td></tr>
                                </tbody></table><br><br>
                            <p></p>
                            
                            </td>
                        </tr>
                    </tbody></table>';
            $headers = array('Content-Type: text/html; charset=UTF-8');
    
        wp_mail( $to, $subject, $message, $headers );
      } else {
        $results = wp_remote_retrieve_body( $request );
        return json_decode( $results );  
      }
    }

}

I hope you get an idea about How to send e-mail in WordPress.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments