我正在尝试实现一个简单的sendEmails函数,如果可能的话,它会发送HTML,如果没有,它会发送纯文本。但是,由于某种原因,我在文件中出现语法错误,即使我通过在线验证器传递它,例如phpcodechecker,也没有出现任何问题。
确切错误:
解析错误:语法错误,第83行的C:\ xampp \ htdocs .. \ 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);
}?>
答案 0 :(得分:0)
确保打开的代码为“开启”,您有<? $message = ob_get_clean();
这可能是正在发挥作用的事情之一。
将其更改为:
<?php $message = ob_get_clean();
另外,unexpected end of file
表示你在某个地方缺少右括号或者开口括号太多,这可能来自显然是一个包含的文件。
在您发布的代码中只有79行,其中83行。