定制 snipworks/php-smtp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

snipworks/php-smtp

最新稳定版本:v2.0.4

Composer 安装命令:

composer require snipworks/php-smtp

包简介

Simple PHP SMTP Mail Send Script

README 文档

README

An easy to use SMTP (Simple Mail Transfer Protocol) library which helps you to send emails.

Installation

composer require snipworks/php-smtp

Examples

Unsecured

<?php

use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 25);
$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('<b>Example message</b>...');

if($mail->send()){
    echo 'Success!';
} else {
    echo 'An error occurred.';
}

Secured (TLS)

<?php

use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 587);
$mail->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('<b>Example message</b>...');

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

// config.php

define('SMTP_PRIMARY_EMAIL', 'sender@example.com');
define('SMTP_PRIMARY_PASSWORD', 'my very secret password');
<?php

require_once('config.php');
// ...
$mail->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.

统计信息

  • 总下载量: 4.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 86
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 86
  • Watchers: 5
  • Forks: 45
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-13