php - 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>
解决方案
推荐阅读
- python-3.x - Python OpenCV 的 matplotlib.pyplot 有问题
- arduino - 有没有一种更简洁的方法可以只在循环中运行一次动作?
- javascript - 为什么客户端没有收到服务器检索的数据?
- python - 是否有任何人可能熟悉的函数可以使用 Networkx 创建具有周期性边界条件的方形 kagome 晶格?
- r - 包 CARET:具有相同语法的不同输出(方法:“knn”和“mlpKerasDecay”)
- unity3d - Unity 无法使用滚动条滚动文本输入框
- sql - How to display the name of an attribute if it is spelled differently in the same table in sql
- r - 转换数据框以绘制 R 中的交互效果
- c++ - 为什么我的带有“?:”的 cout 语句在“:”之后没有进入其他部分
- c++ - 将 rdbuf() 打印到控制台有效,但 getline 失败