تحذير - تتطلب بعض الميزات في هذه الصفحة متصفحًا أو نظام تشغيل أحدثًا من المتصفح الذي تستخدمه حاليًا.إذا كان لديك متصفح آخر متاح ، فافتح هذه الصفحة به.
Send Email using the SMTP Client
وثائق API
Send Email
SMTP Commands
معلومات
رمز المثال
Email Sent, SMTP Log
Email Error, SMTP Log
- This page allows you to see a live example of communication between the SMTP Client and widely used SMTP Servers.
- Select an SMTP Server from the list and then the code shown below will be called.
- At times there will be a delay. This is likely a forced delay from the SMTP Server to slow down and block spammers. The call that is delayed will clearly show in the log result.
- Typically SMTP is simply used for sending outgoing emails however basic commands can be used by an automated script to verify if the server is working correctly.
// Optional Debug callback to log SMTP calls and reply lines
$reply_lines = [];
$debug_callback = function($message) use (&$reply_lines) {
$reply_lines[] = '[' . date('H:i:s') . '] ' . trim($message);
};
// Create SMTP Object and call serveral commands (API methods)
$smtp = new SmtpClient($host, $port, $timeout, $debug_callback);
$smtp->help();
$smtp->noop();
$smtp->quit();
$smtp->close();
Why use FastSitePHP for SMTP and Email
- Easy to use API
- Great performance and minimal memory needed
- All SMTP and Email code exists in only small 2 files (each file a separate class). All code is well commented and there is no magic code. For security it’s clear what is going on with the code.
- Classes are designed around security and reliability, while supporting needed email features
- Unicode Support including for using Unicode email addresses
- Easy to include file attachments
- Easy for debugging SMTP communication (send and reply commands)
Other PHP SMTP Email Clients
FastSitePHP only supports SMTP. If you need to use [sendmail], encoding other than UTF8, DKIM, Auth using XOAUTH2, or an un-supported email feature one of the following widely used PHP projects is recommended.
SMTP Clients in other Programming Languages
- JavaScript (Node) https://nodemailer.com/about/
- Python https://docs.python.org/3/library/smtplib.html
- Ruby Mail https://rubygems.org/gems/mail/
- Ruby SMTP https://ruby-doc.org/stdlib/libdoc/net/smtp/rdoc/Net/SMTP.html
- C# / .Net https://docs.microsoft.com/en-us/dotnet/api/system.net.mail
- Go Lang https://golang.org/pkg/net/smtp/
// Create an Email Object. The Email Object can also
// be created without specifying any parameters.
$email = new \FastSitePHP\Net\Email($from, $to, $subject, $body);
// All properties can be read and set through getter/setter functions.
$email
->allowUnicodeEmails(true) // For support with Unicode Email Addresses
->from(['无回复@example.com', 'No Reply'])
->replyTo('test@example.com')
->to(['email1@example.com', 'email2@example.com'])
->cc('email3@example.com')
->bcc('email4@example.com')
->priority('High') // ['High', 'Normal', or 'Low']
->safeHeaderNames(true) // Defaults to [true] for custom fields
->header('X-Transaction-ID', '123abc')
->encodeFileNames(true)
->attachFile($file_path)
->isHtml(true) // Defaults to [true]
->subject($subject)
->body($body);
// Send email using Simple Mail Transfer Protocol (SMTP).
// Setting [$smtp = null] after use, automatically calls [$smtp->quit()]
// and [$smtp->close()], however it also happens automatically after the
// object is no longer used.
$smtp = new \FastSitePHP\Net\SmtpClient($host, $port);
if ($user) {
$smtp->auth($user, $password);
}
$smtp->send($email);
$smtp = null;
// Create a Client with a 2 second timeout and with debugging
// to show all data sent to the SMTP Server and all reply lines
$timeout = 2;
$callback = function($message) {
echo '[' . date('H:i:s') . '] ' . trim($message) . "\n";
};
$smtp = new \FastSitePHP\Net\SmtpClient($host, $port, $timeout, $callback);