0
<?php


// 载入脚本
// ========================================

require '../functions.php';
require '../static/assets/vendors/mailer/class.phpmailer.php';
require '../static/assets/vendors/mailer/class.smtp.php';

// 访问控制
// ========================================

// 获取登录用户信息
xiu_get_current_user();

// 处理提交请求
// ========================================
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  setemail();
}
function setemail()
{
  $sql = 'select bir,email FROM users ';
  $bir_email = xiu_query($sql);
  $arr = array( );
  $b=date('m/d');
  foreach ($bir_email as $item) {
    $timestamp = strtotime($item['bir']);
    $a = date('m/d', $timestamp);
    if ($a === $b) {
      $arr[$item['email']] = $item['bir'];
    }
  }

  // $timestamp = strtotime($current_use['bir']  );
  // $a = date('m/d', $timestamp);
  //  echo strtotime($a );
  // $b=date('m/d');
  // echo strtotime($b );


  // foreach ($variable as $key => $value) {
  //   $mail->addAddress($key);
  // }

  if (empty($_POST['title']) || empty($_POST['content'])) {
    $GLOBALS['message'] = '请完整填写所有内容';
    return;
  }
 var_dump($arr);
 date_default_timezone_set('PRC');
 ignore_user_abort();
 set_time_limit(0);
 $interval = 60*1;
 do{
   $mail = new PHPMailer();
   $mail->SMTPDebug =3;
   $mail->isSMTP();
   $mail->SMTPAuth=true;
   $mail->Host = 'smtp.qq.com';
   $mail->SMTPOptions = array(
   'ssl' => array(
       'verify_peer' => false,
       'verify_peer_name' => false,
       'allow_self_signed' => true
       )
   );
   $mail->SMTPSecure = 'ssl';
   //设置ssl连接smtp服务器的远程服务器端口号 可选465或587
   $mail->Port = 465;
   $mail->Hostname = 'localhost';
   $mail->CharSet = 'UTF-8';
   $mail->FromName = 'XXXXXX';
   $mail->Username ='xingyang0320@foxmail.com';
   $mail->Password = 'ipstvtuisxwaeche';
   $mail->From = 'xingyang0320@foxmail.com';
   $mail->isHTML(true);
   $mail->addAddress('2010055685@qq.com');
   $mail->Subject = '这是一个PHPMailer发送邮件的示例';
   $mail->Body = "这是一个<b style=\"color:red;\">PHPMailer</b>发送邮件的一个测试用例";
   // $mail->addAttachment('./src/20151002.png','test.png');
   $status = $mail->send();
   if($status)
   {
   echo '发送邮件成功'.date('Y-m-d H:i:s');;
   }
   else
   {
   echo '发送邮件失败,错误信息未:'.$mail->ErrorInfo;
   }
   sleep($interval);//休眠1minute
 }while(true);
}
 ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Add new post &laquo; Admin</title>
  <link rel="stylesheet" href="/static/assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="/static/assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="/static/assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="/static/assets/vendors/simplemde/simplemde.min.css">
  <link rel="stylesheet" href="/static/assets/css/admin.css">
  <script src="/static/assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.php"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="logout.php"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="page-title">
        <h1>生日邮件</h1>
      </div>
      <?php if (isset($message)) : ?>
      <div class="alert alert-danger">
        <strong>错误!</strong><?php echo $message; ?>
      </div>
      <?php endif; ?>
      <form class="row" action="<?php echo $_SERVER['PHP_SELF'];?>"  method="post" >
        <div class="col-md-9 ">
          <div class="form-group">
            <label for="title">标题</label>
            <input id="title" class="form-control input-lg" name="title" type="text" value="<?php echo isset($_POST['title']) ? $_POST['title'] : ''; ?>" placeholder="文章标题">
          </div>
          <div class="form-group">
            <label for="content">内容</label>
            <textarea id="content" class="form-control input-lg" name="content" cols="30" rows="10"  placeholder="内容"><?php echo isset($_POST['content']) ? $_POST['content'] : 'ddfsdfc'; ?></textarea>
            <!-- <script id="content" name="content" type="text/plain">123</script> -->
          </div>
          <div class="form-group">
            <button class="btn btn-primary" type="submit">保存</button>
          </div>
        </div>
      </form>
    </div>
  </div>

  <?php $current_page = 'send-email'; ?>
  <?php include $current_user['email'] ==='admin@xy.me' ? 'inc/sidebar_adm.php' : 'inc/sidebar_user.php' ; ?>

  <script src="/static/assets/vendors/jquery/jquery.js"></script>
<script src="/static/assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>

  </script>
  <script>NProgress.done()</script>
</body>
</html>

clipboard.png
不加发邮件部分就不会卡死 这是为啥

2019-04-28 提问
1 个回答
0

你那do while不是个死循环么。。。。

撰写答案

推广链接