jv-conseil/dkim-php-mail-signature
Composer 安装命令:
composer require jv-conseil/dkim-php-mail-signature
包简介
🔏 Stand-alone DKIM class to sign your emails with a 2048 bit private key hashed with SHA-256 algorithm.
README 文档
README
🔏 Stand-alone DKIM class to sign your emails with a 2048 bit private key hashed with SHA-256 algorithm.
Usage
Sample lines to import into your mail code to start signing with DKIM:
require_once __DIR__ . '/../vendor/autoload.php' ; // Autoload files using Composer autoload use JVconseil\DkimPhpMailSignature\DKIMsign ; use JVconseil\DkimPhpMailSignature\DKIMconfig ; // init $config = new DKIMconfig('/www/inc/config/jv-conseil/dkim-php-mail-signature/config.inc.php') ; $sign = new DKIMsign( $config->private_key, $config->passphrase, $config->domain, $config->selector ) ; // sign $signed_headers = $sign->get_signed_headers($to, $subject, $message, $headers) ; // send email mail($to, $subject, $message, $signed_headers.$headers) ;
Installation
Step by Step guide to generate your encryption keys and populate them through your DNS records.
Installation & loading
DkimPhpMailSignature is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install DkimPhpMailSignature. Just add this line to your composer.json file:
"jv-conseil/dkim-php-mail-signature": "^1.0"
or run
composer require jv-conseil/dkim-php-mail-signature
Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of DkimPhpMailSignature.
Make your own copy of config file
Before starting you should make a copy of folder config/ and store it outside your vendor/ Composer repository in a non-public area of your website e.g.:
/www/inc/config/jv-conseil/dkim-php-mail-signature/
Failing to do so will expose you to lose all your settings in case of a future Composer udpate.
Generate your Public & Private Encryption keys
In Terminal enter this command line to start working under the path of your config/ folder:
cd /www/inc/config/jv-conseil/dkim-php-mail-signature/
In Terminal enter this command line to generate a new private 2048 bit encryption key:
openssl genrsa -des3 -out private.pem 2048
Enter your Pass Phrase and save it for editing your config.inc.php file in the next step.
Then retrieve your public key:
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
You can delete the two originals *.pem file keys stored in the config/ folder if they create a conflict in the creation process of your keys.
Edit your DNS with a new DKIM record
Access your registrar interface (e.g.: OVH.com) and create a new DKIM record to declare your public key:
selector._domainkey IN TXT ( "v=DKIM1;k=rsa;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ekggNf9vuzzL4SlVc8QZyyqbEwR5bVTPC9cEZ8hFqTKOc7go180n3RZilYJZvveaxBkLCVJSTQaMPtKuSptY5au6Pi3AkFlizzhUJ80+0zgZXSGx7gfbginbRwhD+XdGOe9NXpo0PfrD6dEJ49Ytx4/nHB0TKiL227C0kGWb7RfWTVWccgJq4+kQb4l+4" "oDU5rGomSYK+zmMV13QTSETcJnoXhmjoJ30omyJfEXAsK5Ny0LJo8rWCucLD31BxHrM9/+M/Ye+TWxcrD2mRh5Jxqcnyj00/7kCnWeGPTftVKkAJBP3JMRqCNShLUchLhaz0qeXUtxAe9dx7ltr8042QIDAQAB;" )
DKIM works better with SPF and DMARC records, you should consider editing them too:
3600 IN TXT "v=spf1 include:_spf.google.com ~all" _dmarc IN TXT "v=DMARC1; p=quarantine; rua=mailto:me@yourdomain.name"
Further reading:
- Add DKIM domain key to domain DNS records
- Manage suspicious emails with DMARC
- Help prevent email spoofing with SPF records
Edit your Config File
Under config/config.sample.inc.php you will find a config file example to help you set your own details.
Now you can drop .sample in the filename and start editing it:
- domain: your domain name e.g: google.com
- selector:
selectorused in your DKIM DNS record, e.g.: selector._domainkey.MAIL_DKIM_DOMAIN - passphrase: your pass phrase used to generate your keys e.g.: myPassPhrase.
- ... other parameters can be omitted.
Simple Use
Sample lines to import into your mail code to start signing with DKIM:
require_once __DIR__ . '/../vendor/autoload.php' ; // Autoload files using Composer autoload use JVconseil\DkimPhpMailSignature\DKIMsign ; use JVconseil\DkimPhpMailSignature\DKIMconfig ; // init $config = new DKIMconfig('/www/inc/config/jv-conseil/dkim-php-mail-signature/config.inc.php') ; // set: this calls __set() $config->domain = "mynewdomain.name" ; // get: this calls __get() $config->domain ; // => "mynewdomain.name" ;
Introducing DKIMmail class
📬 Stand-alone class to send DKIM signed emails with a 2048 bit private key hashed with SHA-256 algorithm.
// init $mail = new DKIMmail('/www/inc/config/jv-conseil/dkim-php-mail-signature/config.inc.php') ; // parameters $mail->from = "Sender" <sender@yourdomain.com> ; $mail->to = "Recipient" <recipient@yourdomain.com> ; $mail->subject = "Your Mail Subject" ; $mail->body = "Your Mail Message." ; $mail->attach("/path/to/your/attachment.jpg", "NameOfYourAttachment.jpg") ; // send! $mail->send() ;
Documentation
Documentation is available online, though it may not be quite up to date or match your version exactly.
You can generate API documentation by running phpdoc in the top-level folder of this project, and documentation will be generated in this folder:
php ~/vendor/bin/phpdoc -d ~/dkim-php-mail-signature/ -t ~/dkim-php-mail-signature/docs/
You will need to have phpDocumentor installed.
Sponsorship
If this project helps you reduce time to develop, you can give me a cup of coffee ☕️ :-)
jv-conseil/dkim-php-mail-signature 适用场景与选型建议
jv-conseil/dkim-php-mail-signature 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.47k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「composer」 「spf」 「packagist」 「dmarc」 「dkim」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jv-conseil/dkim-php-mail-signature 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jv-conseil/dkim-php-mail-signature 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jv-conseil/dkim-php-mail-signature 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WordPress mu-plugin to set sender/return path for mail if not set..
This authres_status plugin checks the Authentication-Results headers of your emails and displays the verification status. The verification status is displayed when you read an email, but you can also add a column to your message list.
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
Checks for configured mail athentication methods like SPF, DKIM and DMARC
统计信息
- 总下载量: 1.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: EUPL-1.2
- 更新时间: 2019-11-17
