CodefyPHP FrameworkCodefyPHP Framework
  • Home
  • Community
    • Forum
    • Github
    • YouTube
  • News
  • Home
  • Community
    • Forum
    • Github
    • YouTube
  • News
home/Knowledge Base/Helpers/mail
Popular Search:installation, codex, mail

mail

35 views 0

Written by Joshua
September 5, 2024

Description

An alternative to using PHP's native mail function with other options for SMTP (default), Qmail, and Sendmail.

Usage

<?php

use function Codefy\Framework\Helpers\mail;

mail(string|array $to, string $subject, string $message, array $headers = [], array $attachments = []): bool;

Parameters

$to (string|array) (required) Email recipient(s).

$subject (string) (required) Subject of the email.

$message (string) (required) The email body.

$headers (array) (optional) An array of headers to include.

$attachments (array) (optional) Attachments to include.

Return Value

(bool) Returns false on error or true if no error occurred.

Example

<?php

use function Codefy\Framework\Helpers\mail;
use function Codefy\Framework\Helpers\storage_path;

$to = ['test@example.com' => 'Recipient Name'];
$subject = 'Email Message';
$message = 'This is a <strong>simple</strong> email message.';
$headers = [
    'cc' => [
        'recipientone@example.com' => 'Recipient One',
        'recipienttwo@example.com' => 'Recipient Two'
    ],
    'bcc' => ['another@example.com' => 'Another Recipient'],
];
$attachments = [storage_path('file.pdf')];

mail(to: $to, subject: $subject, message: $message, headers: $headers, attachments: $attachments);
Edit on Github

Last Updated on September 5, 2024 by Joshua

Related Articles
  • sort_element_callback
  • php_where
  • php_like
  • convert_array_to_object
  • compact_unique_array
  • truncate_string

Didn't find your answer? Check out the Forum

Leave A Comment Cancel reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  sort_element_callback

  • Copyright 2025 CodefyPHP.com. All Rights Reserved

Popular Search:installation, codex, mail