How to make confirmation of PHP post office
Learn how to create a simple email verification system with PHP & example code.
Confirming PHP Post Office
PHP Post Office is an open source library for sending emails with PHP. It allows developers to quickly and easily create, send, and track emails without the need for any third-party software. This tutorial will show you how to confirm that your emails are being sent using PHP Post Office.
First, you'll need to add the PHP Post Office library to your project. You can do this either by downloading the library from GitHub, or by using Composer to install it from Packagist. Once you have the library installed, you can add it to your project using the following code:
require_once 'path/to/PHPPostOffice/autoload.php';
Next, you need to create an instance of the PHP Post Office class. This can be done by passing an array of options to the constructor. For example:
$mailer = new PHPPostOfficePHPPostOffice([
'host' => 'smtp.example.com',
'port' => 465,
'username' => 'username',
'password' => 'password',
]);
Once the instance is created, you can use the send
method to send an email. This method takes two parameters - an array of options, and an instance of the Message
class. The options array should contain the following keys: to
, subject
, body
, and headers
. For example:
$options = [
'to' => '[email protected]',
'subject' => 'Test Email',
'body' => 'This is just a test email',
'headers' => [
'From' => '[email protected]',
],
];
$message = new PHPPostOfficeMessage();
$mailer->send($options, $message);
The send
method will return a boolean true
or false
value, which indicates whether the email was sent successfully or not. You can use this value to confirm that your emails are being sent.
If you want to confirm that the email was actually delivered to the recipient's mailbox, you can use the getDeliveryStatus
method. This method takes one parameter - the email address of the recipient. It will return an array of information about the delivery status of the email, including the date it was sent, the status of the delivery, and more. For example:
$deliveryStatus = $mailer->getDeliveryStatus('[email protected]');
By using the send
and getDeliveryStatus
methods, you can easily confirm that your emails are being sent and delivered using PHP Post Office.