首页 > 解决方案 > Is it possible to update the PHP version of my web template to be up to date with my hosting service?

问题描述

my problem is that (to my understanding) the RD-Mailform.php and html code in my webpage for the RD-mailform are written with older versions of PHP, and therefore will not work with the server I am hosting my webpage on, which is version 7.3.20. Ultimately my goal is to simply have my contact forms on my webpage work.

I have tried swapping the entire mailform code in dreamweaver to see if I could at least get a different error message; same error. I have tried changing a small line of code (line 11) in the rd-mailform.php from: $recipients = $formConfig['myemail@gmail.com']; (my personal email is filled out) to: $recipients = 'myemail@gmail.com'; this changed my browser error from - MF001 (Recipients are not set!) to MF004 (Please, define type of your form!)

I do not understand how to define my form type. Please advise me on what I am overlooking and or if I am not understanding quite properly what the real issue is. (I can provide the mailform.json file code if necessary as well.

Here is the rd-mailform code I am looking at:

    <?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 = 'postersemail@mail.com';

    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\} -->)(.|\s)*?(<!-- #\{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');
}

HTML Code below, added 07/30/20 - 5:38 am

<!-- RD Mailform-->
          <form class="rd-form rd-mailform" data-form-output="form-output-global" data-form-type="contact" method="post" action="bat/rd-mailform.php">
            <div class="row row-20">
              <div class="col-md-4">
                <div class="form-wrap form-wrap-icon input--nao">
                  <input class="form-input input__field--nao" id="contact-name" type="text" name="name" data-constraints="@Required">
                  <label class="form-label mdi mdi-account-outline input__label--nao" for="contact-name">Your Name</label>
                  <svg class="graphic graphic--nao" width="300%" height="100%" viewbox="0 0 1200 60" preserveaspectratio="none">
                    <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path>
                  </svg>
                </div>
              </div>
              <div class="col-md-4">
                <div class="form-wrap form-wrap-icon input--nao">
                  <input class="form-input input__field--nao" id="contact-email" type="email" name="email" data-constraints="@Email @Required">
                  <label class="form-label input__label--nao mdi mdi-email-outline" for="contact-email">E-mail</label>
                  <svg class="graphic graphic--nao" width="300%" height="100%" viewbox="0 0 1200 60" preserveaspectratio="none">
                    <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path>
                  </svg>
                </div>
              </div>
              <div class="col-md-4">
                <div class="form-wrap form-wrap-icon input--nao">
                  <input class="form-input input__field--nao" id="contact-phone" type="text" name="phone" data-constraints="@Numeric">
                  <label class="form-label input__label--nao mdi mdi-tablet-android" for="contact-phone">Phone</label>
                  <svg class="graphic graphic--nao" width="300%" height="100%" viewbox="0 0 1200 60" preserveaspectratio="none">
                    <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path>
                  </svg>
                </div>
              </div>
              <div class="col-12">
                <div class="form-wrap form-wrap-icon input--nao">
                  <textarea class="form-input input__field--nao" id="contact-message" name="message" data-constraints="@Required"></textarea>
                  <label class="form-label input__label--nao mdi mdi-message-text-outline" for="contact-message">Your Message</label>
                  <svg class="graphic graphic--nao" width="300%" height="50%" viewbox="0 0 1200 60" preserveaspectratio="none">
                    <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path>
                  </svg>
                </div>
              </div>
              <div class="col-12 text-center form-button">
                <button class="button button-primary button-nina" type="submit">Send Message</button>
              </div>
            </div>
          </form>
        </div>
      </section>

标签: phpmail-form

解决方案


推荐阅读