我正在尝试实现一个简单的sendEmails函数,如果可能的话,它会发送HTML,如果不可能的话它会发送纯文本。然而,由于某种原因,我在文件中遇到了语法错误,即使我通过在线验证器(如phpcodechecker)传递它,它也不会出现任何问题。
准确的错误:
分析错误:语法错误,C:''examplep''htdocs中出现意外的文件结尾。。''第83行上的func.php
注意:我只实现了sendEmails功能,它破坏了它
我的代码
<?php
//Input: Email | Output: Boolean for Domain Existence (such as @yahoo.com) [TESTED]
function domainExists($email, $record = 'MX'){
list($user, $domain) = explode('@', $email);
return checkdnsrr($domain, $record);
}
function sendEmails($to, $type, $link){
switch($type){
case "register":
if(strlen($link)>0) $authenticationLink = $link;
else throwError("Email Failed",1);
//Send Email
$subject = "Thank You For Registering";
$boundaryHash = md5(date('r',time()));
$headers = "From: admin@....com";
$headers .= "'r'nContent-Type: multipart/alternative; boundary='"PHP-alt-".$boundaryHash."'"";
ob_start();
?>
--PHP-alt-<?php echo $boundaryHash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Thank you for registering with ...!
We hope you enjoy our service! To get started, please authenticate your account by copying and pasting the following link:
<?php echo $authenticationLink; ?>
--PHP-alt-<?php echo $boundaryHash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<h2>Thank You For Registering!</h2>
<p>Thank you for registering with ...!</p>
<p>We hope you enjoy our service! To get started, please authenticate your account with the following link:</p>
<a href="<?php echo $authenticationLink; ?>">Click to Authenticate</a>
--PHP-alt-<?php echo $boundaryHash; ?>--
<?
$message = ob_get_clean();
$mail_sent = mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
break;
default: break;
}
return;
}
//isEscaped(String, Con):boolean, [TESTED]
function isEscaped($str, $con){
return (mysqli_real_escape_string($con, $str) === $str);
}
//Type: | 0: Unknown Error | 1: | 2: DB Error | 3: Security Issue - Unescaped |
//String: | 'Fatal' | 'NonFatal' | 'Trivial' | Otherwise String will be output
//[TESTED]
function throwError($str, $type){
//Making sure parameters are valid
$t = (int)$type;
$s = (string)$str;
//Shorthand to auto output general errors
switch ($s){
case 'Fatal':
$s = "FATAL ERROR: Please contact the administrator immediately!";
break;
case 'NonFatal':
$s = "ERROR: Please contact the administrator!";
break;
case 'Trivial':
$s = "Unexpected Error: Please go back and try again!";
break;
}
echo "<p class='errorspan'>".$s.": ".$t."</p>";
exit($t);
}?>
确保打开的标签为"ON",您就有了<? $message = ob_get_clean();
,这可能是其中一个因素。
更改为:
<?php $message = ob_get_clean();
另外,unexpected end of file
意味着某个地方缺少右大括号,或者左大括号太多,这可能来自于一个明显包含的文件。
你发布的代码中只有79行,共83行。