电子邮件发送正常,但我收到消息$ body未定义?

时间:2018-01-10 11:40:05

标签: php mysql email

所以我有一个系统,你可以在其中添加成员到你的组,电子邮件似乎发送完全没有所有信息,但我收到一个错误,说明$ body是一个未定义的变量,任何建议?

   <?php //check member Email matches
$addmember = $link->query("SELECT Email FROM logins WHERE Email ='$memberemail'")->fetch_assoc()['Email'];


$to = $addmember;
$subject = "Becoming part of $leaguename";
            $body.="So you want to become part of $leaguename?".PHP_EOL;
            $body.="Please click the link below to join!".PHP_EOL;
            $body.="http://www.wesbitelink.dev/verify.php?memberemail=$memberemail;".PHP_EOL;

            $headers = "From: localhost";

            mail($to, $subject, $body, $headers);
          header("location: addanothermember.php");

  ?>

我收到的错误消息是:

Notice: Undefined variable: body

2 个答案:

答案 0 :(得分:1)

首先在你可以在这个变量上附加东西之后创建$ body变量

 <?php //check member Email matches
$addmember = $link->query("SELECT Email FROM logins WHERE Email ='$memberemail'")->fetch_assoc()['Email'];


$to = $addmember;
$subject = "Becoming part of $leaguename";
            $body="So you want to become part of $leaguename?".PHP_EOL;
            $body.="Please click the link below to join!".PHP_EOL;
            $body.="http://www.wesbitelink.dev/verify.php?memberemail=$memberemail;".PHP_EOL;

            $headers = "From: localhost";

            mail($to, $subject, $body, $headers);
          header("location: addanothermember.php");

  ?>

试试这个

答案 1 :(得分:1)

这是因为您在.=之前$body上使用$body已定义。将第一个.=更改为仅=或之前定义$body

请参阅http://php.net/manual/en/language.operators.string.php

中有关字符串运算符的手册