How to create header in mail slim
In Mail Slim, you can create a header by using the header
method. Here is an example:
$headers = array(
'From' => '[email protected]',
'To' => '[email protected]',
'Subject' => 'Hello from Mail Slim',
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8'
);
$mail = new Mail();
$mail->headers($headers);
$mail->body('Hello, this is a test email.');
$mail->send();
In this example, we create an array of headers and pass it to the headers
method of the Mail
object. The headers
method sets the headers of the email message.
You can also use the header
method to set individual headers:
$mail->header('From', '[email protected]');
$mail->header('To', '[email protected]');
$mail->header('Subject', 'Hello from Mail Slim');
Note that the header
method overwrites any existing header with the same name. If you want to add a header without overwriting any existing headers, you can use the addHeader
method:
$mail->addHeader('From', '[email protected]');
$mail->addHeader('To', '[email protected]');
$mail->addHeader('Subject', 'Hello from Mail Slim');
The addHeader
method adds the header to the end of the list of headers, rather than overwriting any existing headers with the same name.