Категория: PHP. Сеть. Почта
Sending Emails in PHP with PHPMailer
PHPMailer is one of the most popular open source PHP libraries to send emails with. It was first released way back in 2001 and since then it has become a PHP developer’s favorite way of sending emails programmatically, aside from a few other fan favorites like Swiftmailer.
In this article we’ll talk about why you should use PHPMailer instead of PHP’s
mail() function and we’ll show some code samples on how to use this library.
Is it an alternative to PHP’s
In most cases, it’s an alternative to PHP’s
mail() function, but there are many other cases where the
mail() function is simply not flexible enough to achieve what you need.
First of all, PHPMailer provides an object oriented interface, whereas
mail() is not object oriented. PHP developers generally hate to create
$headers strings while sending emails using the
mail() function because they require a lot of escaping — PHPMailer makes this a breeze. Developers also need to write dirty code (escaping characters, encoding and formatting) to send attachments and HTML based emails when using the
mail() function whereas PHPMailer makes this painless.
mail() function requires a local mail server to send out emails. PHPMailer can use a non-local mail server (SMTP) if you have authentication.
Further advantages include:
Подробнее: Sending Emails in PHP with PHPMailer (Отправка почты)