duanjiongzhen2523 2017-04-12 22:20
浏览 28
已采纳

从txt列表发送邮件时的php延迟

i have this script for sending mails from a emails.txt list and is working fine but is there a way to delay the sending of emails from the list? Any help is appreciated,thanks!

This is the Php sender script:

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.">
";
       $headers .= "Bcc: $bcc
";
       $headers .= "Reply-To: ".$reply_to_email."
";
       $headers .= "MIME-Version: 1.0
";
       $headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uid."\"

";

$message = "--PHP-mixed-$uid
"."Content-Type: multipart/alternative; boundary=\"PHP-alt-$uid\"

";
$message .= "--PHP-alt-$uid
"."Content-Type: text/plain; charset=\"iso-8859-1\"
"."Content-Transfer-Encoding: 7bit

";

//Insert the html message.
 $message .= $mesaj;
 $message .="

--PHP-alt-$uid--

";

//include attachment
$message .= "--PHP-mixed-$uid
"."Content-Type: $file_type; name=\"$file_name\"
"."Content-Transfer-Encoding: base64
"."Content-Disposition: attachment

";
$message .= $encoded_content;
$message .="Content-Transfer-Encoding: base64
";
$message .="X-Attachment-Id: ".rand(1000,99999)."

"; 
$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 fields:

<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>
  • 写回答

1条回答 默认 最新

  • doqo89924 2017-04-12 22:23
    关注

    you can use the sleep() command to pause it

    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)
            }  
    

    for example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错