我是PHP新手,最近我在系统中使用Composer安装了PHPMailer。我正在尝试发送的HTML邮件遇到问题。
我已经尝试发送纯文本,它工作正常,并得到了PHPmailer的响应。
下面是我的代码:
<?php
require_once 'autoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'email@exapmle.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->From="mailer@example.com";
$mail->FromName="My site's mailer";
$mail->Sender="mailer@example.com";
$mail->AddReplyTo("replies@example.com", "Replies for my site");
$mail->AddAddress("receiver@example.com");
$mail->Subject = "Test 1";
$mail->IsHTML(true);
$mail->Body = '<html>
<head>
<link href="http://alikan.esy.es/Untitled1.css" rel="stylesheet">
<link href="http://alikan.esy.es/index.css" rel="stylesheet">
<script src="http://alikan.esy.es/jquery-1.11.1.min.js"></script>
<script src="http://alikan.esy.es/fancybox/jquery.easing-1.3.pack.js"></script>
<link rel="stylesheet" href="http://alikan.esy.es/fancybox/jquery.fancybox-1.3.0.css">
<script src="http://alikan.esy.es/fancybox/jquery.fancybox-1.3.0.pack.js"></script>
<script src="http://alikan.esy.es/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script src="http://alikan.esy.es/wwb10.min.js"></script>
</head>
<body>
<div id="wb_Text1" style="position:absolute;left:223px;top:70px;width:250px;height:16px;z-index:0;text-align:left;">
<span style="color:#000000;font-family:Arial;font-size:13px;"><a href="javascript:displaylightbox('http://www.google.com/index.php',{width:1000,height:1000})" target="_self">This is an email body</a></span></div></body></html>';
$mail->AltBody="This is text only alternative body.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
echo "Letter is sent";
}
?>这是我在尝试发送后得到的错误代码:
( ! ) Parse error: syntax error, unexpected 'http' (T_STRING) in C:\wamp\www\vendor\index.php on line 37发布于 2015-06-14 20:59:45
您使用单引号'打开了正文字符串
$mail->Body = '<html>...然后在html字符串中再次使用它来声明一个参数:
...javascript:displaylightbox('http://www.google.com/index.php',...如果您的字符串由单引号或双引号分隔,如果它包含相同的字符,则必须对其进行转义,否则php解析器会认为您的字符串在下一次出现开始引号时结束。如果在内容中用单引号分隔,使用双引号而不转义,则可以,反之亦然。
通过以下方式对这两个'进行转义:
...javascript:displaylightbox(\'http://www.google.com/index.php\',...编辑:
此外,如果您发送的是HTML体,请记住在发送邮件之前设置isHTML标志:
$mail->IsHTML(true);https://stackoverflow.com/questions/30829520
复制相似问题