电子邮件正文未显示(swift 邮件程序 PHP)
email body is not showing up (swift mailer PHP)
我正在使用 swift 邮件程序通过 'gmail' 发送电子邮件验证,但问题是我收到一封没有正文的空白电子邮件,
Here is what I get in my email :
这是我的代码:
<?php
require_once './vendor/autoload.php';
require_once './config/constants.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.googlemail.com', 465, 'ssl'))
->setUsername(EMAIL)
->setPassword(PASSWORD)
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
function sendEmailVerification($userEmail, $userToken){
global $mailer;
$body = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<p>
Thank you for Signing in to ESP. Please click on the link below to Verify your Account.
</p>
<a href="http://localhost/eps/login.php?token='. $userToken .'">Verify your Acount</a>
</div>
</body>
</html>
`;
// Create a message
$message = (new Swift_Message('Verify Your email'))
->setFrom( EMAIL )
->setTo($userEmail)
->setBody($body)
->setContentType('text/html')
;
// Send the message
$mailer->send($message); //tried also $result = $mailer->send($message);
}
?>
任何解决方案请!
请将反引号(`)改为单引号('):
$body = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<p>
Thank you for Signing in to ESP. Please click on the link below to Verify your Account.
</p>
<a href="http://localhost/eps/login.php?token='. $userToken .'">Verify your Acount</a>
</div>
</body>
</html>
';
这个概念更多的是变量插值。
其中字符串可以用单引号或双引号引起来。
如果我们必须在字符串中的任何元素周围添加双引号,我们可以用单引号开始该字符串,反之亦然。
请查看以下语法,所有 3 个都是正确的:
echo '<div class="myCls" id="myId">Some Content Here</div>';
和
echo "<div class='myCls' id='myId'>Some Content Here</div>";
和
echo "<div class=\"myCls\" id=\"myId\">Some Content Here</div>";
// Escaping the characters with '\' character.
至少对我来说,我更喜欢第一个。
我正在使用 swift 邮件程序通过 'gmail' 发送电子邮件验证,但问题是我收到一封没有正文的空白电子邮件, Here is what I get in my email : 这是我的代码:
<?php
require_once './vendor/autoload.php';
require_once './config/constants.php';
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.googlemail.com', 465, 'ssl'))
->setUsername(EMAIL)
->setPassword(PASSWORD)
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
function sendEmailVerification($userEmail, $userToken){
global $mailer;
$body = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<p>
Thank you for Signing in to ESP. Please click on the link below to Verify your Account.
</p>
<a href="http://localhost/eps/login.php?token='. $userToken .'">Verify your Acount</a>
</div>
</body>
</html>
`;
// Create a message
$message = (new Swift_Message('Verify Your email'))
->setFrom( EMAIL )
->setTo($userEmail)
->setBody($body)
->setContentType('text/html')
;
// Send the message
$mailer->send($message); //tried also $result = $mailer->send($message);
}
?>
任何解决方案请!
请将反引号(`)改为单引号('):
$body = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<p>
Thank you for Signing in to ESP. Please click on the link below to Verify your Account.
</p>
<a href="http://localhost/eps/login.php?token='. $userToken .'">Verify your Acount</a>
</div>
</body>
</html>
';
这个概念更多的是变量插值。
其中字符串可以用单引号或双引号引起来。
如果我们必须在字符串中的任何元素周围添加双引号,我们可以用单引号开始该字符串,反之亦然。
请查看以下语法,所有 3 个都是正确的:
echo '<div class="myCls" id="myId">Some Content Here</div>';
和
echo "<div class='myCls' id='myId'>Some Content Here</div>";
和
echo "<div class=\"myCls\" id=\"myId\">Some Content Here</div>";
// Escaping the characters with '\' character.
至少对我来说,我更喜欢第一个。