I have written some code to make an email automatically send to the email address of the user at the click of a button. But for some reason is it not sending any emails, I have tested it with two different email addresses.
Code for button:
form action="sendellie.php" method="post">
<input type="submit" value="Buy tickets"/>
</form>
Code for processing page:
<?php
session_start();
    include 'connect.php';
     ini_set("sendmail_from", "********");
    $user_id= $_SESSION['id'];
    $sql = "SELECT username FROM user WHERE user_id = '$user_id'";
    $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    $uname = mysql_fetch_array($result);
     $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    $uemail = mysql_fetch_array($result);
    $user_id= $_SESSION['id'];
    $sql = "SELECT email FROM user WHERE user_id = '$user_id'";
    $result = mysql_query($sql) or die('Query failed. ' . mysql_error());
    $uemail = mysql_fetch_array($result);
     while($row = mysql_fetch_array($result))
     {
        $name = $uname['username'];
        $email = $uemail['email'];
        $message = "This email is to confirm you have purchased one Ellie Goulding Ticket for the O2";
        $subject = $uname['username'];
        echo "sent to"." ".$email." ".$subject." ".$message."<p />";
        mail($email, $subject, $message);
        }
        echo "Go check your mail box:";
        include 'close.php';
        ?>
    <?php echo $uemail['email'] ?><br>
    <a href="ellie.php">Back</a>
 
     
     
    