【问题标题】:Emails are sending fine but I receive the message $body is undefined? [duplicate]电子邮件发送正常,但我收到消息 $body 未定义? [复制]
【发布时间】:2018-01-10 11:40:04
【问题描述】:

所以我有一个系统,您可以在其中将成员添加到您的组,并且电子邮件似乎发送完全正常并且包含所有信息,但是我收到一个错误,指出 $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

【问题讨论】:

  • 在开始向其添加内容之前,您没有创建 $body 变量

标签: php mysql email


【解决方案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");

  ?>

试试这个

【讨论】:

【解决方案2】:

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

请参阅http://php.net/manual/en/language.operators.string.php 上有关字符串运算符的手册

【讨论】:

猜你喜欢
  • 2017-12-05
  • 2014-09-13
  • 2017-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-07
  • 1970-01-01
  • 2014-07-20
相关资源
最近更新 更多