等待变量在php邮件函数

时间:2017-06-27 15:46:22

标签: php email

我正面临一个案例,我有一个php页面,它将一些变量结果发送到一个电子邮件地址,这很有效,但现在在发送电子邮件之前我需要等待一个变量然后执行电子邮件。 varibales组让我们称之为D组和2个变量Z group

如果在第一个变量等待的时候,如何在同一个php页面上填充这个变量。

B必须等待2小时才变量未达到它必须发送电子邮件,除此之外,如果用户在2小时之前转发D组,则重写并将小时数设置为0并等待Z组试。

<?php

$datetime1 = new DateTime('2017-06-27 08:00:00');
$datetime2 = new DateTime();
 $interval = $datetime1->diff($datetime2);
//echo $interval->format('%h');
if ($interval->format('%h') > 2 ) {
echo "yes more than 2 hours";
 } else {
 echo "not more than 2 hours";
// 12 hours are up
// give your error message
}
?>

考虑时间间隔以获得2小时不同然后创建另一个if条件比较另一个变量是否存在所以这就是我想出的。

 <?php
$groupD = $_GET["info"];
$datetime1 = new DateTime('2017-06-27 08:00:00');
sleep(1800);  // sleep for 30 mins awaiting
$groupz = $_GET["infoxx"];
$datetime2 = new DateTime();
$interval = $datetime1->diff($datetime2);
//echo $interval->format('%h');


if ($interval->format('%h') > 2 ) {
if (!is_null($groupD) & !is_null($groupz)){
    echo "execute mail";
}
else {
    echo "wont execute";
}

} else {
 echo "not more than 2 hours";
// 12 hours are up
 // give your error message
}

&GT;

这个问题我面临的是如何保持组D等待直到组Z到达相同的php页面,我设置睡眠30分钟因为2小时是最大的应该等于变量,如何测试。

这是我的邮件脚本///(我收到的变量来自某些js脚本,通过数组中的ajax)

>?php 
 $mail = $_GET["info"];
    //sleep(60);
    foreach ($mail as $gtm) {
   $message .= $gtm;
    }
    $header ="From: no-reply@test.com" . "\r\n";
    $para    = 'web2@test.com';
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $titulo  = 'Mailing list Newsletter';

    $message = '<html><body>';
    $message .= '<br/> <p>El siguiente usuario abandono el la compra de un paquete en booking hello </p><br/>';
    $message .= '<table rules="all" style="border-color: #666;" cellpadding="2">';
    $message .= "<tr><td><strong>Nombre del paquete:</strong> </td><td>" .  $mail[0] ."</td></tr>";
    $message .= "<tr><td><strong>Precio Total del paquete:</strong> </td><td>" .  $mail[1] ."</td></tr>";
    $message .= "<tr><td><strong>Nombre:</strong> </td><td>" .  $mail[2] ."</td></tr>";
    $message .= "<tr><td><strong>Apellido:</strong> </td><td>" .  $mail[3] ."</td></tr>";

    $message .= "</table>";
    $message .= "</body></html>";



       if(mail($para, $titulo, $message, $header)){
                die();
        }else{
        //echo "false";
       }

      /*    }else{
        echo "false";
        }


     */

      }
   ?>

1 个答案:

答案 0 :(得分:1)

非常直接的方法是需要到达特定页面的文件首先应该写入某个tmp文件 - arrived.txt

需要等待的文件是轮询(即每5秒,最多两个小时),以查看文件arrived.txt是否为EMPTY,而不管其中的内容是什么。

  • 如果它不为空,则:清空文件并DO ACTION X

  • 如果为空,则:DO ACTION Y

修改

以下是写入文件的方法:

$file = 'temp.txt';
file_put_contents($file, "Arrived");

以下是检查文件是否为空的方法:

if(filesize($filename) > 0) {
    //file not empty...
    //DO ACTION X
} else {
    //file is empty...
    //DO ACTION Y
}

以下是每5秒民意调查的方法

for ($i=0; $i <= 120; $i++) {
    if(filesize($filename) > 0) {
        //file not empty...
        //DO ACTION X
    } else {
        //file is empty...
        //DO ACTION Y
    }
    sleep(5); //wait 5 seconds
}