0

So I have a form in which you can ask someone to join your group via email and for some reason it's not sending the emails out, it was working perfectly fine yesterday and now something seems to be broken. This is the form:

<div class="form" style="background: white; box-shadow: 0 0px rgba(0, 0, 0, 0);">
    <form id="addmember" action="addingmember.php" method="post" autocomplete="off">
        <div class="field-wrap">
            <label style="position: relative; color: black;">
                Member Email:
            </label>
            <input type="email" required autocomplete="off" name="memberemail"
                   style="color: black; padding: 8px; height: 48px;"/>
        </div>
        <button type="submit" class="button button-block" name="submit">
            Submit
        </button>
    </form>

And this is the addingmember code:

<?php

include '../db_connection.php';

session_start();

$leaguename = $_SESSION['league_name'];
$startdate = $_SESSION['start_date'];
$enddate = $_SESSION['end_date'];
$joincode = $_SESSION['joincode'];

$_SESSION['memberemail'] = $_POST['memberemail'];

$memberemail = $link->escape_string($_POST['memberemail']);

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

$to = $memberemail;
$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.linkhere.com/login/verify.php?memberemail=$memberemail&joincode=$joincode;" . PHP_EOL;

$headers = "From: emailhere";

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

?>
Rwd
  • 27,979
  • 5
  • 47
  • 62
Phoebe
  • 27
  • 1
  • 8
  • check you spam.. – Akhil VL Jan 05 '18 at 10:27
  • Do you have a mail server? otherwise the mail can not be sent – Melody Jan 05 '18 at 10:27
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Jan 05 '18 at 10:27
  • @Melody I'm using Mercury & Thunderbird as a local mail server currently, so my register emails and changing password emails all work – Phoebe Jan 05 '18 at 10:32
  • @Phoebe —Thunderbird is not a mail server. When you say Mercury, do you mean http://www.pmail.com ? – Quentin Jan 05 '18 at 10:35
  • @Quentin Yeah, it works alongside Xampp and I have been receiving all other emails so it's not the server, and so I've narrowed it down to being in this part of the code – Phoebe Jan 05 '18 at 10:38
  • Is a mail adress in the variable $membermail? Have you checked this? – Melody Jan 05 '18 at 10:39
  • @Melody It seems to echo fine up until after the query – Phoebe Jan 05 '18 at 11:02

1 Answers1

0
$memberemail = $link->query("SELECT Email FROM logins WHERE Email =' " . $_SESSION['memberemail'] . "'")->fetch_assoc()['memberemail'];

You basically select "Email" in the query, but want to get "memberemail" from it instead. Maybe this is the issue.

Add a check for that $memberemail variable.

Also, it is a bit dangerous to use $_SESSION['memberemail'] in the query without escaping it.

Cat
  • 121
  • 6
  • $memberemail value works up until the query and the query is supposed to be calling Email as thats the name of the column in the database it's pulling from. – Phoebe Jan 05 '18 at 11:04
  • @Phoebe Yeah, that's the name of the column, but you're trying to get a different name here: `->fetch_assoc()['memberemail']` – Cat Jan 05 '18 at 11:15
  • Okay so I changed it to Email just to check but I'm still getting Null when checking $memberemail – Phoebe Jan 05 '18 at 11:19
  • @Phoebe Ok. Do the query check in _another variable_, not `$memberemail`. Check `$memberemail` value before it enters the query. Afterwards, see the result of the query. – Cat Jan 05 '18 at 11:31
  • $memberemail is the correct value before it enters the query and I changed the variable but I am still getting Null after the query – Phoebe Jan 05 '18 at 11:40
  • You mean the query result is null? – Cat Jan 05 '18 at 12:03