How to add css when mail send content in php

When sending an email using PHP, you can add CSS styles to the email content using a few different methods. Here are a few approaches:

Method 1: Inline Styles

You can add inline styles to the HTML content of the email using the style attribute. For example:

$html = '<p style="color: #00698f; font-size: 16px;">This is a paragraph of text.</p>';

This will add the specified styles to the paragraph of text.

Method 2: External Stylesheet

You can link to an external stylesheet using the link tag. For example:

$html = '<link rel="stylesheet" type="text/css" href="styles.css">';

Then, in your styles.css file, you can define the styles you want to apply to the email content. For example:

body {
  font-family: Arial, sans-serif;
  font-size: 16px;
  color: #333;
}

p {
  color: #00698f;
  font-size: 16px;
}

Method 3: Embedded Stylesheet

You can embed a stylesheet directly into the HTML content using the style tag. For example:

$html = '<style type="text/css">
  body {
    font-family: Arial, sans-serif;
    font-size: 16px;
    color: #333;
  }

  p {
    color: #00698f;
    font-size: 16px;
  }
</style>';

This will add the specified styles to the email content.

Example Code

Here's an example of how you might use one of these methods to add CSS styles to an email sent using PHP:

<?php

// Set the email content
$html = '<p style="color: #00698f; font-size: 16px;">This is a paragraph of text.</p>';

// Set the email headers
$headers = array(
    'From' => 'Your Name <[email protected]>',
    'Subject' => 'Test Email',
    'Content-Type' => 'text/html; charset=UTF-8'
);

// Set the email body
$body = $html;

// Send the email
mail('[email protected]', 'Test Email', $body, $headers);

?>

In this example, we're using the style attribute to add inline styles to the email content. You can modify this code to use an external stylesheet or embedded stylesheet instead.