1
我正在爲主要聯繫人表單編寫一個腳本,需要將前10個導聯發送給電子郵件1,第二個導聯到電子郵件2,等等,直到到達電子郵件4,然後它回到電子郵件1.如何構建一個PHP轉子
這是一個旋轉器我已經爲着陸頁建成,但它每次旋轉1次,而不是等待10次,然後旋轉。我如何修改這個以適應我的需求?
另外,它顯然不能在每一次「刷新」時發生。需要有一組獨立的代碼,這些代碼將會在表單的action =「whatever.php」中出現,並且代碼將會增加它。
<?php
//these are the email addresses to be rotated
$email_address[1] = '[email protected]';
$email_address[2] = '[email protected]';
$email_address[3] = '[email protected]';
$email_address[4] = '[email protected]';
//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();
?>
[在PHP數組是零索引。](http://php.net/manual/en/language.types.array.php) – 2012-02-08 04:37:37