Registration email showing default mail message as well new custom message How to stop default mail , i want to override default mail with my custom body message?
Here is my code :
function mag_api_mail_alter(&amp;$message) {
  // only alter register forms
  if (!empty($message['id']) &amp;&amp; $message['id'] == 'user_register_no_approval_required') {

  // make it a bit neater to access fields
    
    $nids = \Drupal::entityQuery('node')-&gt;condition('type','email_template')-&gt;execute();
    $nodes =  \Drupal\node\Entity\Node::loadMultiple($nids);
    $data_fields = array();
    foreach ($nodes as $new_data){
        $data_fields[] = $new_data-&gt;get('body')-&gt;getValue();
    }
    $contact_message = $message['params']['account'];
    $first_name = $contact_message-&gt;field_first_name-&gt;value;
    $username_email = $contact_message-&gt;get('name')-&gt;value;
    $pass = 'test';
    $app_url = 'abcd.com';
    
    /*custom field added through configuration*/
    
    $to_replace_keys = array(&quot;[user_name]&quot;,&quot;[user_email]&quot;,&quot;[user_password]&quot;,&quot;[app_url]&quot;);
    $replace_keys =array($first_name,$username_email,$pass,$app_url);
    $success_email_msg = str_replace($to_replace_keys, $replace_keys,$data_fields[0][0]['value']);
    // Assigning new message to mail body.
    $message['body'][] = $success_email_msg;
    
   }
}

Its is working but i am not able to find out why is this showing default mail message as well new body message.
I just want to show my custom body message.
$message['body'][] = $success_email_msg; is appending your variable to the existing array. You'll need to remove the default content from the $message['body'] array if you don't want it
e.g. unset($message['body']['whateverkey']) to remove a specific part. Or $message['body'] = [$success_email_msg]; to reinitialise the variable as a new array