我已经在我的网站上实施了Reusableforms,除了在客户端查看收到的电子邮件之外,所有内容都运行正常,电子邮件始终来自“联系表单”'电子邮件' forms@domain.com'。
如何更改此选项以显示通过表单发布的发件人姓名和电子邮件?以下是reusableforms包含的handler.php中的代码。
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['Name','Email'])->areRequired()->maxLength(50);
$validator->field('Email')->isEmail();
$validator->field('Message')->maxLength(6000);
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('0000000000000000000000000000000');
$pp->sendEmailTo('orders@domain'); // ← Your email here
echo $pp->process($_POST);
答案 0 :(得分:0)
我也一直在寻找这方面的帮助。
我有这个工作 - 偶然 - 有两个实例 &#39; $ pp = new FormHandler();&#39;。
请参阅下面的代码版本。
我不明白为什么会这样。
<?php
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
/* The next 7 lines must be in this 1st section */
$mailer = $pp->getMailer();
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->SMTPSecure ="ssl";
$mailer->Host = "serverxxx.xxxx.com";
$mailer->Username = "contact@xxxxxxx.com";
$mailer->Password = "xxxxxxxxxxxxxx";
/* The next 2 lines work whether in the 1st or 2nd section */
$pp->requireReCaptcha();
$pp->getReCaptcha()->initSecretKey('xxxxxxxxxxxx');
/* Section 2
I do not understand it, but without the 2nd '$pp = new FormHandler()' below,
the SMTP send fails. The reported error is:
Sorry there was an error sending your form.
mail:SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have tested changing the 2nd $pp to $pp2 and it also works.
*/
$pp = new FormHandler();
/* The next line has to be in this 2nd section.
If it is the last line in top section then it appears to be sent OK
but the email does not actually arrive.
Checking the SMTP logs shows it was never sent.*/
$pp->sendEmailTo(['leslie@xxxxxxxxxxx.com']);
/* The next 2 lines also must be here rather than in 1st section above. */
$mailer = $pp->getMailer();
$mailer->setFrom('contact@xxxxxxx.com','xxxxxxx Contact Form');
echo $pp->process($_POST);
答案 1 :(得分:0)
要在 ReusableForm 上向用户电子邮件地址发送回复,您需要从 handler.php 获取值,并使用 addReplyTo 函数和 $_POST 全局将其添加到“setFrom”函数上方的 FormHandler.php变量:
$this->mailer->addReplyTo($_POST['Email']);
$this->mailer->setFrom($from_email,'Contact Form',false);
这些表单在 2021 年使用 PHP 7.3 仍然可以正常工作