解析错误:语法错误,C:\ xampp \ htdocs \ Project \ lost-password.php中出现意外的':',期望为','或')'
<?php
if(isset($_POST["forgot_pass"])){
$email = mysqli_real_escape_string($connection,$_POST['email']);
$query ="SELECT *FROM users WHERE user_email = '{$email}' ";
$for_query = mysqli_query($connection,$query);
if(mysqli_num_rows($for_query)>0){
$str = "0123456789acdsvfetryuhgbhjikolpmnbva";
$str = str_shuffle($str);
$str = substr($str,0,10);
$up_query = "UPDATE users SET token='$str', token_expire=DATE_ADD(NOW(), INTERVAL 5 MINUTE) WHERE user_email= '{$email}'";
$update_q = mysqli_query($connection,$up_query);
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/Exception.php";
$mail =new PHPMailer();
$mail->addAddress($email);
//getting error here
$mail->setFrom( address: 'exa@example.com', name: 'ABC');
$mail->Subject = 'Reset Password';
//getting error here
$mail->isHTML(isHtml: true);
$mail->Body="
Hi,<br><br>
In order to reset your password, please click on the link below:<br>
<a href=>n</a><br><br> ";
?>
答案 0 :(得分:8)
您正在传递命名参数,但是那些东西在PHP中不存在。所以不要这样做:
$mail->setFrom( address: 'exa@example.com', name: 'ABC');
您应调用以下方法:
$mail->setFrom('exa@example.com', 'ABC');
您还应该对$mail->isHTML(isHtml: true)
做同样的事情,将其更改为$mail->isHTML(true)