https://github.com/snipworks/php-smtp
Simple PHP SMTP Mail Send Script
https://github.com/snipworks/php-smtp
php smtp
Last synced: 23 days ago
JSON representation
Simple PHP SMTP Mail Send Script
- Host: GitHub
- URL: https://github.com/snipworks/php-smtp
- Owner: snipworks
- License: mit
- Created: 2014-05-23T01:33:11.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2020-09-06T10:15:16.000Z (over 5 years ago)
- Last Synced: 2025-09-21T05:57:49.121Z (7 months ago)
- Topics: php, smtp
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 85
- Watchers: 5
- Forks: 45
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP SMTP
========
An easy to use SMTP (Simple Mail Transfer Protocol) library which helps you to send emails.
## Installation
```bash
composer require snipworks/php-smtp
```
## Examples
### Unsecured
```php
setLogin('sender@example.com', 'password');
$mail->addTo('recipient@example.com', 'Example Receiver');
$mail->setFrom('example@example.com', 'Example Sender');
$mail->setSubject('Example subject');
$mail->setHtmlMessage('Example message...');
if($mail->send()){
echo 'Success!';
} else {
echo 'An error occurred.';
}
```
### Secured (TLS)
```php
setProtocol(Email::TLS);
$mail->setLogin('sender@example.com', 'password');
$mail->addTo('recipient@example.com', 'Example Receiver');
$mail->setFrom('example@example.com', 'Example Sender');
$mail->setSubject('Example subject');
$mail->setHtmlMessage('Example message...');
if($mail->send()){
echo 'Success!';
} else {
echo 'An error occurred.';
}
```
It's discouraged to hard-code the SMTP login credentials like in the examples above.
It's recommended to put them inside another file and load it or set it to environment variable
```php
setLogin(SMTP_PRIMARY_EMAIL, SMTP_PRIMARY_PASSWORD);
// ...
```
It's also recommended to put the config outside the public web root if possible.
This for example prevents people from including your PHP file remotely by a misconfiguration.