邮件代码无效

时间:2016-04-19 08:43:00

标签: php email

我已经编写了一个代码,用于邮件用户作为用户查看此页面的时间,或者用这个页面加载时的简单文字,使用会话变量和代码没有任何问题或错误,但邮件不在所有都是由指定用户收到的。请帮帮我。

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> 

在上面提到的代码中,邮件部分位于顶部,具体如下代码!

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 个答案:

答案 0 :(得分:0)

如果您从未从服务器成功发送过代码(使用复制/粘贴代码),请确保您的Web主机允许通过电子邮件发送。

许多/大多数免费的,甚至一些付费的人禁用它。

答案 1 :(得分:0)

我不相信你需要围绕着地址的引号。

将其替换为$ to = $ _SESSION [&#39; email&#39;];

然后按照建议检查您的电子邮件日志(如果您正在运行邮件程序)。还尝试使用PHP邮件从简单的脚本向该用户发送电子邮件 - 是否发送?这可能是你最好的选择,因为你可以看看它是你的标题还是只是一般。

同时检查用户的垃圾邮件文件夹,如果它被标记为垃圾邮件。