通过刷新页面或使用crontab运行查询

时间:2014-05-30 11:51:48

标签: php arrays forms function

我今天创建了一个脚本,用于通过php转发电子邮件地址。 表格很好地帮助了它。

我的脚本中有一个提交按钮,当我点击提交按钮时,它会将邮件发送到指定的电子邮件地址。

但我想通过刷新页面http://gonplay.info/time/index.php

来做到这一点
  

我是PHP的新手,请查看我的脚本并提供详细帮助。

对不起英语不好并提前致谢。

<HTML>
<HEAD>
<TITLE>imap_check</TITLE>
</HEAD>
<BODY>
<?php
     //check for new messages

     $mailbox = imap_open("{pop.gmail.com:995/pop/ssl}INBOX",
             "XXXXXXXXX@gmail.com","PASSWORD");

     // Check messages
     $check = imap_check($mailbox);

     // show headers for messages

     $index=1;


      $header = imap_header($mailbox, $index);

  //Extract TO Name and Address
  $to = $header->to;
  foreach ($to as $id => $object) {
      $toname = $object->personal;
      $toaddress = $object->mailbox . "@" . $object->host;
}     
  //Extract Sender Name and Address
  $from = $header->from;
  foreach ($from as $id => $object) {
      $fromname = $object->personal;
      $fromaddress = $object->mailbox . "@" . $object->host;
}
  $subject=$header->Subject;
      $message = imap_fetchbody($mailbox,$index,1);

     imap_close($mailbox);

$rets = "<form action=\"index.php\" method=\"POST\">";
    $rets .= "<input type=\"hidden\" name=\"parse_var\" value=\"Mail\">";
    $rets .= "<input type=\"hidden\" name=\"toname\" value=\"$toname\">";
    $rets .= "<input type=\"hidden\" name=\"toaddress\" value=\"$toaddress\">";
    $rets .= "<input type=\"hidden\" name=\"fromname\" value=\"$fromname\">";
    $rets .= "<input type=\"hidden\" name=\"fromaddress\" value=\"$fromaddress\">";
    $rets .= "<input type=\"hidden\" name=\"subject\" value=\"$subject\">";
    $rets .= "<input type=\"hidden\" name=\"message\" value=\"$message\">";
    $rets .= "<input type=\"Submit\" name=\"Submit\" Value=\"Submit\"></form>";
    echo $rets;

 if ($_POST['parse_var'] == "Mail"){
$toname = $_POST['toname'];
$toaddress = $_POST['toaddress'];
$fromname = $_POST['fromname'];
$fromaddress = $_POST['fromaddress'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$body = <<<EOD
$message
EOD;

//Email to
$to = "$toname <joyahm@gmail.com>";// Change with your email address.

//Email Subject
$subject = "$subject";// Change with your email subject.

//Email Header
$headers = "From: $fromname <$fromaddress>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$success = mail("$to", "$subject", "$body", "$headers");
}
?>
</BODY></HTML>

1 个答案:

答案 0 :(得分:0)

这不是一个真正的php问题,而是一个unix / windows,(或者你正在使用的任何服务器),问题。

您可以设置一个cron作业来调用页面或定期运行脚本。

修改

删除代码

$rets = "<form action=\"index.php\" method=\"POST\">";
....

删除if语句,(但不删除内容)。

if ($_POST['parse_var'] == "Mail"){
  ....
} 

对值进行硬编码,(之前在if语句中)

$toname = 'whatever';
$toaddress = 'whatever';
$fromname = 'whatever';
$fromaddress = 'whatever';
$subject = 'whatever';
$message = 'whatever';
...
$success = mail("$to", "$subject", "$body", "$headers");

就是这样。