如何构建PHP旋转器


How to build a PHP rotator

我正在为潜在客户联系人表单编写一个脚本,该表单需要将前10个潜在客户发送到电子邮件1,第二个10个潜在用户发送到电子邮件2,依此类推,直到它到达电子邮件4,然后返回电子邮件1。

这是我为着陆页构建的旋转器,但它每次旋转1次,而不是等待10次,然后再旋转。我该如何修改以满足我的需求?

此外,很明显,它不可能在每次"刷新"时都发生。需要有一组单独的代码,这些代码将进入表单的action="whatever.php"中,这是将增加它的代码。

<?php
//these are the email addresses to be rotated
$email_address[1] = 'email1@email.com';
$email_address[2] = 'email2@email.com';
$email_address[3] = 'email3@email.com';
$email_address[4] = 'email4@email.com';
//this is the text file, which will be stored in the same directory as this file, 
//count.txt needs to be CHMOD to 777, full privileges, to read and write to it.
$myFile = "count.txt";
//open the txt file
$fh = @fopen($myFile, 'r');
$email_number = @fread($fh, 5);
@fclose($fh);
//see which landing page is next in line to be shown.
if ($email_number >= count($email_address)) {
    $email_number = 1;
} else {
    $email_number = $email_number + 1;
}
//write to the txt file.
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $email_number . "'n";
fwrite($fh, $stringData);
fclose($fh);
//include the landing page
echo $email_address[$email_number]; 
//terminate script
die();
?>

我从你的问题中了解到,有一个表格可以提交潜在客户,当提交潜在客户时,它必须遵循你的逻辑。如果我错了,请纠正我。

如果是这种情况,使用两个类似track.txt的文本文件。该文本文件的初始内容为1,0。这意味着线索被发送到第一个电子邮件id 0次。

因此,在动作脚本的表单中包含以下代码。

<?php
$email_address[1] = 'email1@email.com';
$email_address[2] = 'email2@email.com';
$email_address[3] = 'email3@email.com';
$email_address[4] = 'email4@email.com';
$myFile = "track.txt";
//open the txt file
$fh = @fopen($myFile, 'r');
$track = @fread($fh, 5);
@fclose($fh);
$track = explode(",",$track);
$email = $track[0];
$count = $track[1];
if($count >= 10)
{
  $count=0;
  if($email >= count($email_address))
  {
    $email = 1;
  }
  else
  {
    $email++;
  }
} 
else
{
  $count++;
}
$track = $email.",".$count;
//write to the txt file.
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $track);
fclose($fh);
//send lead to $email

?>