douqie3391 2019-06-14 03:32
浏览 69

如何在php上设置rd联系表单?

I have a trouble on setting a rd contact form. I checked some online tutorials said that find the ( bat/rd-mailform.php ) file, locate the ( $recipients = '#'; ), replacing # with my email. But it was not working.

I have 1 html file, 1 php file (rd-mailform.php), 1 TPL file (rd-mailform) and 1 JSON file (re-mailform.congfig).


  1. below is rd-mailform.config.json file.
{
  "useSmtp": false,
  "host": "stmp.gmail.com",              
  "port": 465,                                                   
  "username": "demo@gmail.com",                  
  "password": "demopassword",                        
  "recipientEmail":  "demo@gmail.com"        
}

  1. below is rd-mailform.php
$formConfigFile = file_get_contents("rd-mailform.config.json");
$formConfig = json_decode($formConfigFile, true);

date_default_timezone_set('Etc/UTC');

try {
require './phpmailer/PHPMailerAutoload.php';

$recipients = $formConfig['recipientEmail'];

preg_match_all("/([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\. 
([a-z]{2,6}(?:\.[a-z]{2})?)/", $recipients, $addresses, 
PREG_OFFSET_CAPTURE);

if (!count($addresses[0])) {
die('MF001');
}

function getRemoteIPAddress() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    return $_SERVER['HTTP_CLIENT_IP'];

} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
return $_SERVER['REMOTE_ADDR'];
}

if (preg_match('/^(127\.|192\.168\.)/', getRemoteIPAddress())) {
die('MF002');
}

$template = file_get_contents('rd-mailform.tpl');

if (isset($_POST['form-type'])) {
switch ($_POST['form-type']){
    case 'contact':
        $subject = 'A message from your site visitor';
        break;
    case 'subscribe':
        $subject = 'Subscribe request';
        break;
    case 'order':
        $subject = 'Order request';
        break;
    default:
        $subject = 'A message from your site visitor';
        break;
    }
    }else{
    die('MF004');
    }

    if (isset($_POST['email'])) {
    $template = str_replace(
    array("<!-- #{FromState} -->", "<!-- #{FromEmail} -->"),
    array("Email:", $_POST['email']),
    $template);
    }

    if (isset($_POST['message'])) {
    $template = str_replace(
    array("<!-- #{MessageState} -->", "<!-- #{MessageDescription} -- 
    >"),
    array("Message:", $_POST['message']),
    $template);
    }

    preg_match("/(<!-- #{BeginInfo} -->)(.|
)+(<!-- #{EndInfo} -- 
    >)/", $template, $tmp, PREG_OFFSET_CAPTURE);
    foreach ($_POST as $key => $value) {
    if ($key != "counter" && $key != "email" && $key != "message" && 
    $key != "form-type" && $key != "g-recaptcha-response" && 
    !empty($value)){
    $info = str_replace(
        array("<!-- #{BeginInfo} -->", "<!-- #{InfoState} -->", "<!-- 
    #{InfoDescription} -->"),
        array("", ucfirst($key) . ':', $value),
        $tmp[0][0]);

    $template = str_replace("<!-- #{EndInfo} -->", $info, $template);
    }
    }

    $template = str_replace(
    array("<!-- #{Subject} -->", "<!-- #{SiteName} -->"),
    array($subject, $_SERVER['SERVER_NAME']),
    $template);

    $mail = new PHPMailer();


    if ($formConfig['useSmtp']) {
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();

    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 0;

    $mail->Debugoutput = 'html';

    // Set the hostname of the mail server
    $mail->Host = $formConfig['host'];

    // Set the SMTP port number - likely to be 25, 465 or 587
    $mail->Port = $formConfig['port'];

    // Whether to use SMTP authentication
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";

    // Username to use for SMTP authentication
    $mail->Username = $formConfig['username'];

    // Password to use for SMTP authentication
    $mail->Password = $formConfig['password'];
    }

    $mail->From = $addresses[0][0][0];

    # Attach file
    if (isset($_FILES['file']) &&
    $_FILES['file']['error'] == UPLOAD_ERR_OK) {
    $mail->AddAttachment($_FILES['file']['tmp_name'],
    $_FILES['file']['name']);
    }

    if (isset($_POST['name'])){
    $mail->FromName = $_POST['name'];
    }else{
    $mail->FromName = "Site Visitor";
    }

    foreach ($addresses[0] as $key => $value) {
    $mail->addAddress($value[0]);
    }

    $mail->CharSet = 'utf-8';
    $mail->Subject = $subject;
    $mail->MsgHTML($template);
    $mail->send();

    die('MF000');
    } catch (phpmailerException $e) {
    die('MF254');
    } catch (Exception $e) {
    die('MF255');
    }

  1. below is HTML file
        <form class="rd-mailform rd-mailform-mod-1" data-form-output="form-output-global" data-form-type="forms" method="post" action="bat/rd-mailform.php">
              <div class="range">
                <div class="cell-sm-6">
                  <div class="form-group">
                    <label class="form-label-outside" for="contact-first-name">First name</label>
                    <input class="form-control" id="contact-first-name" type="text" name="first-name" data-constraints="@Required">
                  </div>
                </div>
                <div class="cell-sm-6 offset-top-18 offset-sm-top-0">
                  <div class="form-group">
                    <label class="form-label-outside" for="contact-last-name">Last name</label>
                    <input class="form-control" id="contact-last-name" type="text" name="last-name" data-constraints="@Required">
                  </div>
                </div>
                <div class="cell-sm-6 offset-top-18">
                  <div class="form-group">
                    <label class="form-label-outside" for="contact-email">E-mail</label>
                    <input class="form-control" id="contact-email" type="email" name="email" data-constraints="@Email @Required">
                  </div>
                </div>
                <div class="cell-sm-6 offset-top-18">
                  <div class="form-group">
                    <label class="form-label-outside" for="contact-phone">Phone</label>
                    <input class="form-control" id="contact-phone" type="text" name="phone" data-constraints="@Required @Numeric">
                  </div>
                </div>
                <div class="cell-xs-12 offset-top-18">
                  <div class="form-group">
                    <label class="form-label-outside" for="contact-message">Message</label>
                    <textarea class="form-control" id="contact-message" name="message" data-constraints="@Required"></textarea>
                  </div>
                </div>
                <div class="cell-xs-12 offset-top-30">
                  <button class="btn btn-primary" type="submit">Send Message</button>
                </div>
              </div>
            </form>
  • 写回答

1条回答 默认 最新

  • douzhi3776 2019-08-08 11:10
    关注

    In order to set up the email address to send the e-mails (sent with the help of RD Mailform @version 3.2.0), please replace in bat/rd-mailform.config.json file, value of recipientEmail field to recipient email.

    You have to give details only on JSON file (rd-mailform.config.json) -->

    {
        "useSmtp": true/false,
        "host": "enter host ",              
        "port": enter port,                                                   
        "username": "enter email id",                  
        "password": "enter password",                        
        "recipientEmail":  "enter recipient email "        
    }
    

    Note: To configure smtp through gmail, you need to give access to unreliable applications

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP