0

So I have a system in which you can add members to your group and the email seems to send completely fine and has all the information but I receive an error which states that $body is an undefined variable, any suggestions?

   <?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");

  ?>

The error message I receive is:

Notice: Undefined variable: body
Phoebe
  • 23
  • 5

2 Answers2

1

first of all create $body variable after you can append stuff on this variable

 <?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");

  ?>

try this

Maulik
  • 877
  • 1
  • 8
  • 17
  • 1
    Code dumps do not make for good answers. You should explain *how* and *why* this solves their problem. I recommend reading, "[How do I write a good answer?"](http://stackoverflow.com/help/how-to-answer) – John Conde Jan 10 '18 at 12:56
  • Questions that are about undefined variables should not be answered. They should be closed as a duplicate of [PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset”](//stackoverflow.com/q/4261133/) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Jan 10 '18 at 12:57
1

It's because your using .= on $body before $body is defined. Change the first .= to just = or define $body before.

See the manual about string operators at http://php.net/manual/en/language.operators.string.php

DigiLive
  • 1,093
  • 1
  • 11
  • 28
  • Questions that are about undefined variables should not be answered. They should be closed as a duplicate of [PHP: “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset”](//stackoverflow.com/q/4261133/) only. See: [Should one advise on off topic questions?](//meta.stackoverflow.com/q/276572/1768232). Off-topic questions can be closed and deleted, which could nullify your contribution anyway. – John Conde Jan 10 '18 at 12:57