我有这个脚本从emails.txt列表发送邮件,并且工作正常,但有没有办法延迟从列表中发送电子邮件? 感谢任何帮助,谢谢!
这是Php发件人脚本:
if($_POST)
{
$recipient_email = '';
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$from_email = filter_var($_POST["sender_email"], FILTER_SANITIZE_STRING);
$bcc = filter_var($_POST["bcc"], FILTER_SANITIZE_STRING);
$reply_to_email = filter_var($_POST["email"], FILTER_SANITIZE_STRING);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$mesaj = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
//Get uploaded file data
$file_tmp_name = $_FILES['my_file']['tmp_name'];
$file_name = $_FILES['my_file']['name'];
$file_size = $_FILES['my_file']['size'];
$file_type = $_FILES['my_file']['type'];
$file_error = $_FILES['my_file']['error'];
$lista = $_FILES['lista']['tmp_name'];
if($file_error > 0)
{
die('Upload error or No files uploaded');
}
$handle = fopen($file_tmp_name,'rb');
// Now read the file content into a variable
$content = fread($file,filesize($file_tmp_name));
// close the file
fclose($handle);
// Now we need to encode it and split it into acceptable length lines
$encoded_content = chunk_split(base64_encode(file_get_contents($file_tmp_name)));
$uid = md5(date('r', time()));
//header
$headers = "From: ".$name." <".$from_email.">\r\n";
$headers .= "Bcc: $bcc\r\n";
$headers .= "Reply-To: ".$reply_to_email."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uid."\"\r\n\r\n";
$message = "--PHP-mixed-$uid\r\n"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$uid\"\r\n\r\n";
$message .= "--PHP-alt-$uid\r\n"."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"."Content-Transfer-Encoding: 7bit\r\n\r\n";
//Insert the html message.
$message .= $mesaj;
$message .="\r\n\r\n--PHP-alt-$uid--\r\n\r\n";
//include attachment
$message .= "--PHP-mixed-$uid\r\n"."Content-Type: $file_type; name=\"$file_name\"\r\n"."Content-Transfer-Encoding: base64\r\n"."Content-Disposition: attachment\r\n\r\n";
$message .= $encoded_content;
$message .="Content-Transfer-Encoding: base64\r\n";
$message .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
$message .= "/r/n--PHP-mixed-$uid--";
$list = fopen($lista, "r");
if ($list) {
while (($line = fgets($list)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Eroare! Nu am putut trimite mailurile.";
}
else
{
echo "Mailurile au fost trimise!";
}
}
fclose($list);
}
}
Html表单字段:
<form enctype="multipart/form-data" method="POST" action="">
<label>Name <input type="text" name="sender_name" /> </label>
</br><label>Mail <input type="email" name="sender_email" /> </label>
<label>Bcc <input type="text" name="bcc" /> </label>
</br><label>Subject <input type="text" name="subject" /> </label>
</br> <label>Message <textarea name="message"></textarea> </label>
</br><label>attachment <input type="file" name="my_file" /></label>
</br><label>Mail list <input type="file" name="lista" /></label>
</br> <label><input type="submit" name="button" value="Fire :)" /></label>
</form>
答案 0 :(得分:1)
你可以使用sleep()命令暂停它
while (($line = fgets($list)) !== false) {
if (!mail($line, $subject, $message, $headers))
{
echo "Eroare! Nu am putut trimite mailurile.";
}
else
{
echo "Mailurile au fost trimise!";
}
sleep(3)
}
例如