Php - T_CONSTANT_ENCAPSED_STRING

时间:2014-01-29 09:22:21

标签: php forms

我有一个简单的php表单提交脚本 由于错误日志显示:

,因此不会发送电子邮件
PHP Parse error:  syntax error, unexpected '"<div style='display: block; w' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in /home/...

在提交结束时,我有一个回音,这可能是导致这个问题的原因:

<?php
$name = $_POST['name'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$formcontent="Name: $name \nSubject: $subject \nMessage: $message";
$recipient = "email@domain.com";
$subject = "Contact";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo
"<body style='margin: 0;'>" .
    "<div style='display: block; width: 100%; height: 100%; background: url(img/bg.jpg) no-repeat; text-align: center; font-family: Arial, Helvetica;'>" .
        "<span style='font-size: 14px; color: #fff; display: block; padding-top: 30px;'>Message sent</span>" . 
        "<a href='index.php' style='text-decoration: none; background: #333; color: #fff; padding: 10px 14px; display: block; margin: 30px auto; width: 100px;'>Home</a>" . 
    "</div>" .
"</body>";
?>

我在SO周围搜索过,最常见的问题是缺失'或。在某个地方,但我看起来,看起来,找不到任何遗漏。任何帮助,谢谢:)

编辑:更新了完整代码。

2 个答案:

答案 0 :(得分:1)

尝试使用此代替表单提交后使用的内容:

echo
'<body style="margin: 0;">' .
    '<div style="display: block; width: 100%; height: 100%; background: url(img/bg.jpg) no-repeat; text-align: center; font-family: Arial, Helvetica;"> '.
        '<span style="font-size: 14px; color: #fff; display: block; padding-top: 30px;">Message sent</span>' . 
        '<a href="index.php" style="text-decoration: none; background: #333; color: #fff; padding: 10px 14px; display: block; margin: 30px auto; width: 100px;">Home</a>' . 
    '</div>' .
'</body>';

答案 1 :(得分:0)

你可以这样做,因为你的html代码中没有变量:

<?php
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    $formcontent="Name: $name \nSubject: $subject \nMessage: $message";
    $recipient = "email@domain.com";
    $subject = "Contact";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>
<body style="margin:0;">
    <div style="display:block; width:100%; height:100%; background:url(img/bg.jpg) no-repeat; text-align:center; font-family:Arial, Helvetica;">
        <span style="font-size:14px; color:#fff; display:block; padding-top:30px;">Message sent</span>
        <a href="index.php" style="text-decoration:none; background:#333; color:#fff; padding:10px 14px; display:block; margin:30px auto; width:100px;">Home</a> 
    </div>
</body>