0

I have written a code for mailing user as an when user view's this page or in simple words when ever this page loads, using session variables and code is not having any issues or error, but mail is not at all received by specified user.Please help me out.!

code.php

<?php
session_start();
$to      =  " '". $_SESSION['email'] ."' ";
$subject = 'Your vault number';
$message = "Your vault number is '". $_SESSION['vault_no'] ."' ";
$headers = 'From: innovation@miisky.com' . "\r\n" .
 'Reply-To: innovation@miisky.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
<?php 
      if(!isset($_SESSION['fullname'])){ 
      header("Location: signin.php");} 
?>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <title>MiiSky | Dashboard</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <!-- Toastr style -->
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">

    <!-- Gritter -->
    <link href="js/plugins/gritter/jquery.gritter.css" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <style>

    </style>

</head>

<body class="body-ani">
    <div id="wrapper">
        <nav class="navbar-default navbar-static-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav metismenu" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element">

                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                            <span class="clear"> <h2><span class="block m-t-xs">Hi! <strong class="font-bold"><?php
                                                    if(isset($_SESSION['fullname'])){
                                                        echo $_SESSION['fullname'];
                                                    }
                                                    ?>
                    </strong>
                             </span></h2>

                        </div>
                        <div class="logo-element">
                            MiiSky
                        </div>
                    </li>

                     <li class="active">
                    <a href="#"><i class="fa fa-user"></i> <span class="nav-label"> Vault number? </span><span class="fa arrow" ></span></a>

                    <ul class="nav nav-second-level collapse">
                        <li>
                        <a><i class="fa fa-edit"></i> <span class="nav-label">Vault number is your unique number.</span></a></li>
                        <li>
                        <a><i class="fa fa-edit"></i> <span class="nav-label">Vault number is important while storing your information!</span></a></li>
                        <li>
                        <a><i class="fa fa-edit"></i> <span class="nav-label">This can be used like your key to unlock your stored information!</span></a></li>
                        <li>
            <a><i class="fa fa-edit"></i> <span class="nav-label">Overall vault number is vital to move further!</span></a></li>

           </ul>




                </ul>

            </div>
        </nav>

        <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
        <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i class="fa fa-bars"></i> </a>
            <form role="search" class="navbar-form-custom" action="search_results.html">
                <div class="form-group">
                    <input type="text" class="form-control" name="top-search" id="top-search">
                </div>
            </form>
        </div>
            <ul class="nav navbar-top-links navbar-right">
                <li>
                    <span class="m-r-sm text-muted welcome-message">Welcome to MiiSky</span>
                </li>
                <li class="dropdown">



                <li>
                    <a href="sign_out.php">
                        <i class="fa fa-sign-out"></i>Lets create your profile!
                    </a>
                </li>
                <!--<li>
                    <a class="right-sidebar-toggle">
                        <i class="fa fa-tasks"></i>
                    </a>
                </li>-->
            </ul>

        </nav>
        <br><div style="font-size:30px; text-align:center;">

                    <p>Please click <a class="hvr-bounce-in" href="download.php" style="text-decoration:none;"><i>here</i></a> and get your vault number now..!!</p>
                    </div>
                    <div>

                    <h2 style="font-size:30px; text-align:center;">Your current address and location</h2>
                    <div id="map"></div>
                    <p style="font-size:15px; text-align:center;"><span id="address"></span></p>
                    <p id="error"></p>
                    <br>





                    </div>
        </div>


            </div>
        </div>

        </div>

</body>
</html> 

In above mentioned code, mailing part is at the top, specifically as below code!

mail.php

<?php
session_start();
$to      =  " '". $_SESSION['email'] ."' ";
$subject = 'Your vault number';
$message = "Your vault number is '". $_SESSION['vault_no'] ."' ";
$headers = 'From: innovation@miisky.com' . "\r\n" .
 'Reply-To: innovation@miisky.com' . "\r\n" .
  'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

2 Answers2

0

If you have never sent code successfully from the server (using copy / pasted code), ensure your web host allows emailing.

Many / most free ones and even some paid ones disable it.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • No.! sir, i have checked out with server ppl mail option is enabled.! –  Apr 19 '16 at 09:20
0

I don't believe you need the quote marks around the to address.

Replace it with $to = $_SESSION['email'];

Then as suggested check your email logs (if you have a mail program running). Also try sending an email from a simple script to that user just using PHP mail - does it send? Thats probably your best bet because you can then see if its your headers or just general.

Also check spam folders on the user incase it was marked as spam.

Ukuser32
  • 2,147
  • 2
  • 22
  • 32