Change font family in send mail codeigniter
To change the font family in a Send Mail function in CodeIgniter, you can use the set_header
method of the email
library to set the Content-Type
header with the desired font family.
Here is an example:
$this->load->library('email');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'your_smtp_host',
'smtp_user' => 'your_smtp_user',
'smtp_pass' => 'your_smtp_pass',
'smtp_port' => 587,
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_header('Content-Type', 'text/html; charset=utf-8; font-family: Arial, sans-serif');
$this->email->from('your_email_from', 'Your Name');
$this->email->to('recipient_email');
$this->email->subject('Test Email');
$this->email->message('<p>This is a test email.</p>');
if (!$this->email->send()) {
echo $this->email->print_debugger();
} else {
echo 'Email sent!';
}
In this example, we set the Content-Type
header to text/html; charset=utf-8; font-family: Arial, sans-serif
, which tells the email client to render the email content in HTML format with the Arial font family.
You can also use the set_header
method to set other headers, such as Content-Transfer-Encoding
or MIME-Version
, if needed.
Alternatively, you can use the set_mail_type
method to set the mail type to html
and then use the set_charset
method to set the character set to utf-8
, and then use the set_font
method to set the font family. Here is an example:
$this->email->set_mail_type('html');
$this->email->set_charset('utf-8');
$this->email->set_font('Arial, sans-serif');
Note that the set_font
method is not a standard method of the email
library, and it may not work in all email clients. The set_header
method is a more reliable way to set the font family.