bitandblack/contact-form
Composer 安装命令:
composer require bitandblack/contact-form
包简介
Making your contact form much safer
README 文档
README
Bit&Black Contact Form
Making your contact form much safer.
What is it for?
The Contact Form script makes your contact form safer. It
- Checks if a form has been submitted in less than 5 seconds and blocks the submit
- Allows only one submit for one session
- Adds a honeypot for spambots
- Checks if IP or email address are known as bad
Installation
This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/contact-form.
Usage
Set up your SMTP connection:
<?php
use ContactForm\Configuration\SMTP;
$smtp = new SMTP('709fc8b0135c1d', '9dbd8257be31c9', 'smtp.mailtrap.io', 2525);
Set up the form and tell the namespace and the names of the fields for the name and the email address:
<?php
use ContactForm\Configuration\Form;
$form = new Form('contact', 'name', 'email');
Init Contact Form then:
<?php
use ContactForm\ContactForm;
$contactForm = new ContactForm($form, $smtp);
Add the logic to validate the submit, init the mail and send the form:
<?php
use ContactForm\Configuration\Mail;
$mailSentInCurrentSubmit = false;
$mailSentInPreviousSubmit = false;
if ($contactForm->isSubmitValid($_POST)) {
$mail = new Mail(
'New message from your website',
'you@example.org',
'There is a message for you: ' . $form->getData('message')
);
$mail
->setReplyToName($form->getName())
->setReplyToMail($form->getEmail())
;
$contactForm->addMail($mail);
$mailSentInCurrentSubmit = $contactForm->sendMail();
}
$mailSentInPreviousSubmit = $contactForm->hasSentMailPreviously();
It's possible to add multiple mails here.
Add the additional fields by calling $contactForm->getAdditionalFields() to you form. For example:
<form action="" method="post">
<input type="text" name="contact[name]" title="Your Name" placeholder="John Doe">
<input type="email" name="contact[email]" title="Your Email Address" placeholder="john.doe@example.org">
<textarea name="contact[message]" title="Your Message" placeholder="Dear Sir or Madame, ..."></textarea>
<button type="submit">Send</button>
<?php echo $contactForm->getAdditionalFields(); ?>
</form>
Add a statement to show a message somewhere on top of your form:
<?php
if ($mailSentInCurrentSubmit || $mailSentInPreviousSubmit) {
echo '
<p>
Your mail has been sent.
</p>
';
}
If you want to see the script all in one take a look in the example folder.
Mailer
Contact Form uses PHPMailer per default. You can set up your own mailer by using $contactForm->setMailer(new MyCustomMailer()). The mailer needs to implement the MailerInterface. When sending mails Contact Form will clone this object to always have the same configuration.
External Spam Validation
Contact Form provides the validation of IP and Email address by the StopFormSpam API. To enable this you need to call $contactForm->addSpamValidation(new \ContactForm\Validate\StopForumSpam()). You can set up your own validation in the same way. Every validation object needs to implement the ValidationInterface.
Help
If you have questions targeting the usage of Contact Form, feel free to contact us under hello@bitandblack.com.
Further information about Bit&Black can be found under www.bitandblack.com.
bitandblack/contact-form 适用场景与选型建议
bitandblack/contact-form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.62k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「spam」 「bot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bitandblack/contact-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bitandblack/contact-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bitandblack/contact-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dialogflow php sdk
Simple captcha generator
reCAPTCHA library
Client library for reCAPTCHA with proxy support, a free service that protects websites from spam and abuse.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Laravel 5.6 Monolog custom telegram channel
统计信息
- 总下载量: 5.62k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2018-07-19