我正在尝试使用html5模板发送电子邮件,我的代码也可以运行,但是显示警告消息
注意:未定义的变量:第2行的C:\ xampp \ htdocs \ farming.com \ mailconfig.php中的消息
<?php
$message.='<!DOCTYPE>';
$message.='<html xmlns="http://www.w3.org/1999/xhtml">';
$message.='<head>';
$message.='<meta name="viewport" content="width=device-width" />';
$message.='<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$message.='<style>
* {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
box-sizing: border-box;
font-size: 14px;
}
img {
max-width: 100%;
}
body {
-webkit-font-smoothing: antialiased;
-webkit-text-size-adjust: none;
width: 100% !important;
height: 100%;
line-height: 1.6;
}';
$message.='</head><body><table class="body-wrap"><tr><td></td><td class="container" width="600"><div class="content"><table class="main" width="100%" cellpadding="0" cellspacing="0"><tr><td class="alert alert-warning">Farmingarms</td></tr><tr><td class="content-wrap"><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="content-block">Hi '.$name.',<br>Your login password has been changed.</td></tr><tr><td class="content-block"> If you believe this is an error, please click on the button below to visit our support portal, through which you can contact our support team</tr></td><br><tr><td class="content-block"><a style="color:white;" href='.$actual_link.' class="btn-primary">Contact Us</a></td></tr><br><tr><td class="content-block">Thanks for choosing Farmingarms.</td></tr></table></td></tr></table><div class="footer"><table width="100%"><tr><td class="aligncenter content-block"><a href="www.farmingarms.com">Unsubscribe</a> from these alerts.</td></tr></table></div></div></td><td></td></tr></table></body></html>';
if(mail($to, $subject, $message, $headers)){
$error = "mail sended successfully";
}
?>
答案 0 :(得分:2)
$message.='<!DOCTYPE>';
在上面的行中,您的代码中存在未定义的变量警告错误。警告错误可以忽略,它们不是关键错误,这就是代码正常运行的原因。 click here to read more about PHP errors。 “在PHP中。”是延续的标志”
说明
$message.='<!DOCTYPE>';
表示您要在变量$ message中添加'<!DOCTYPE>'
,这是您首先需要定义变量$ message。
您可以通过在代码的开头编写$message="";
来完成此操作,也可以像上述答案一样以$message='<!DOCTYPE>';
开头。