我想在 php 中注册后向用户发送电子邮件验证链接。我收到以下错误;
<块引用>致命错误:未捕获的 Swift_RfcComplianceException:给定的邮箱地址 [] 不符合 RFC 2822, 3.6.2。用户数据实际上是插入到数据库中。
下面是我的邮箱验证码;
<?php
require_once 'vendor/autoload.php';
require_once 'config/constants.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.gmail.com', 465, 'ssl'))
->setUsername(EMAIL)
->setPassword(PASSWORD);
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
function sendVerificationEmail($email, $token){
global $mailer;
$body = '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Verify email</title>
</head>
<body>
<div class="wrapper">
<p> Thank you for registrating on our website. Please click on the link below to verify your email</p>
<a href="http://localhost/medxpress-ng/index.php?token= '. $token. '"> Verify your email address</a>
</div>
</body>
</html>';
// Create a message
$message = (new Swift_Message('Verify your email address'))
->setFrom(EMAIL)
->setTo($email)
->setBody($body, 'text/html');
;
// Send the message
$result = $mailer->send($message);
}
?>