1. Products
  2.   Email
  3.   PHP
  4.   PHP-Mail
 
  

Free PHP API to Send Email Messages 

Open Source and Efficient PHP Email Management Library That Enables Software Developers to Compose and Send Email Messages, Add Images and Attachments, Delete Unwanted Messages & so on.

What is PHP-Mail Library?

Aspose.Email Cloud SDK for PHP is highly adaptable and compatible with a variety of email messaging protocols, including SMTP, POP3, and IMAP. The SDK enables software developers to include email message capabilities into a variety of applications, including web-based, mobile, and desktop applications. Overall, the Aspose.Email Cloud SDK for PHP is an excellent solution for developers looking to create powerful and scalable email messaging apps that can manage a huge number of users and messages.

PHP-Mail stands out as a powerful solution designed to make sending emails in PHP applications simple. This application, developed by the Nette framework experts, provides a simple and user-friendly solution to compose and send emails effortlessly. It is packed with useful capabilities, including the ability to generate emails in HTML and plain text formats, attach files, integrate photos directly into the content, and support for SMTP and Sendmail. You can also use custom headers to personalize your emails, improve error handling, and so on.

Nette's Mail PHP Library allows you to easily create and send emails in PHP. The Library stands out due to its simplicity. With just a few lines of code, you can simply write and send emails. Furthermore, the library provides a variety of email sending options, including SMTP and Sendmail, as well as the ability to schedule emails for later delivery. It's a useful tool for software developers who want to streamline email operations in their applications, thanks to its simple API and easy integration possibilities.

Previous Next

Getting Started with PHP-Mail 

The recommended way to install PHP-Mail SDK is via Composer, please use the following command for easy installation.

Install PHP-Mail via Composer

 composer require nette/mail

You can also download it from GitHub and manually install it with ease.

Sending HTML & Plain Text Emails via PHP

The open source PHP-Mail library makes it easy for software developers to compose and send Email messages in HTML as well as in Plain Text inside PHP applications. Generating email messages is effortless with PHP Mail library. You can set the sender, recipient, subject, and body of the email with minimal code. The library fully supports both HTML and plain text email content, allowing software developers to craft visually appealing emails while ensuring compatibility with clients that prefer plain text. The following example shows how easily software developers can send simple email using PHP.

How to Send a Simple Email Message using PHP Code?

use Nette\Mail\Message;
use Nette\Mail\SendmailMailer;

$message = new Message();
$message->setFrom('sender@example.com')
        ->addTo('recipient@example.com')
        ->setSubject('Hello Nette Mail!')
        ->setBody('This is a test email sent using Nette Mail.');

$mailer = new SendmailMailer();
$mailer->send($message);

Add Attachments to Emails via PHP API

Sending files as attachments with an Email messages is a common requirement, and the open source Nette Mail Library makes it a breeze. The library provides a convenient method for attaching files to emails, enhancing the communication capabilities of your application. Software developers can attach files from the local filesystem or provide file contents directly. Embedding images within email content is made easy by Nette Mail. You can specify inline images using CID (Content-ID) references. The following example demonstrates how software developers can attach a file as well as an inline image to an email messages inside PHP applications.

How to Attach a File or an Inline Image to an Email Message via PHP API?

// Attach a file via PHP


$message->addAttachment('/path/to/file.pdf');
$message->addAttachment('report.docx', file_get_contents('/path/to/report.docx'));

// Attach Inline image

$message->setHtmlBody('

Hello

'); $message->addEmbeddedImage('/path/to/image.jpg', 'image_cid', 'image.jpg');

Custom Headers & Better Error Handling

Custom headers play a crucial role in email communication as they allow developers to add additional metadata or control to their messages. Software developers can add custom headers to their email messages using open source PHP-Mail library. Developers can use the addHeader() method, allowing for additional control over the email delivery. The library also provides better error handling mechanisms to handle exceptions that may occur during email sending operations. The following example shows how to add custom headers in an email messages using the PHP API.

How to Add Custom Headers to Email Message using PHP Library?

use Nette\Mail\Message;

$message = new Message();
$message->setFrom('sender@example.com')
        ->addTo('recipient@example.com')
        ->setSubject('Custom Headers Example')
        ->setBody('This is an email with custom headers.');

// Add custom headers
$message->addHeader('X-Custom-Header', 'Value');
$message->addHeader('X-Another-Header', 'Another Value');