gpt4 book ai didi

php - 语法错误,意外 'Â Â Â Â ' (T_STRING)

转载 作者:行者123 更新时间:2023-12-03 22:54:52 25 4
gpt4 key购买 nike

为什么我的 PHP 邮件代码总是给出:

syntax error, unexpected 'Â Â Â Â ' (T_STRING) in C:\xampp\htdocs\GSP\members.php on line 4

<?php
if(!isset($_POST['email'])) {
     
    $email_to = 'kennydharmawan@gmail.com'; //this is line 4
    $email_subject = "GSP Rent Order";
     
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['unit']) ||
        !isset($_POST['startdate']) ||
!isset($_POST['enddate']) ||
        !isset($_POST['telephone']) ||
!isset($_POST['rname']) ||
!isset($_POST['city']) ||
!isset($_POST['adress'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }
     
    $name = $_POST['name'];
    $email_from = $_POST['email'];
    $unit = $_POST['unit'];
    $startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];
    $telephone = $_POST['telephone'];
$rname = $_POST['rname'];
$city = $_POST['city'];
$adress = $_POST['adress'];
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
$phone_exp = "/^[1-9][0-9]{0,15}$/";
  if(!preg_match($string_exp,$name)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$rname)) {
    $error_message .= 'The Recipient Name you entered does not appear to be valid.<br />';
  }
if(!preg_match($string_exp,$city)) {
    $error_message .= 'The City you entered does not appear to be valid.<br />';
  }
if(!preg_match($phone_exp,$telephone)) {
    $error_message .= 'The Phone Number you entered does not appear to be valid.<br />';
  }
  if(strlen($adress) < 2) {
    $error_message .= 'The Adress you entered do not appear to be valid.<br />';
  }
list($dd,$mm,$yyyy) = explode('/',$startdate);
if (!checkdate($mm,$dd,$yyyy)) {
$error_message .= 'The Start Date you entered do not appear to be valid.<br />';
}
list($dd,$mm,$yyyy) = explode('/',$enddate);
if (!checkdate($mm,$dd,$yyyy)) {
$error_message .= 'The End Date you entered do not appear to be valid.<br />';
}
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";
     
    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }
     
    $email_message .= "Name: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Unit: ".clean_string($unit)."\n";
    $email_message .= "Start Date: ".clean_string($startdate)."\n";
    $email_message .= "End Date: ".clean_string($enddate)."\n";
$email_message .= "Telephone Number: ".clean_string($telephone)."\n";
$email_message .= "Recipient Name: ".clean_string($rname)."\n";
$email_message .= "Recipient City: ".clean_string($city)."\n";
$email_message .= "Recipient Adress: ".clean_string($adress)."\n";
     
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

echo "Thank you for contacting us. We will be in touch with you very soon."
}
?>

为什么一直报这个错误?

最佳答案

您的问题是 PHP 文件保存了特殊的空白字符——即不是标准空格,而是一些其他字符呈现为空格(甚至根本不显示),但 PHP 无法解析。

删除第 3 行和第 4 行的所有空白字符,重新键入它们并保存文件。 (这是所有的空白,包括换行符和单词之间的空格)

这应该可以解决问题。

如果执行此操作后,您仍然收到错误,但在不同的行,那么您也需要对该行重复该过程。

关于php - 语法错误,意外 'Â Â Â Â ' (T_STRING),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15067407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com