title: PHP mass sending email script
body: <p>I'm trying to make email mass sender for our users in small local classfieds site. </p>
  
  <p>Idea is:  I use upload.html to upload emails.txt file with list of emails, separated on each line</p>
  
  <p>After upload.html form gets processed by doskaosender.php, it reads the file and and places it in local dir to be processed in the next step. 
  Then I go to send.html,  enter the subject, from, replyTo and the message and click SEND, it get's processed by send.php. In send.php I create the function doskaosendmail wich takes subject, from, replyTo and message and sends single email. </p>
  
  <p>Then I just loop the reading of email.txt, take each line by line and pass the eamil to single sender  doskaosendmail function. </p>
  
  <p>But I got an error in send.php, something goes wrong, and I can't put my finger on what exactly. </p>
  
  <p>The code. </p>
  
  <p><strong>upload.html</strong></p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head lang="en"&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Upload Emails&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2&gt;&lt;p&gt;&lt;b&gt; UPLOAD emails.txt file &lt;/b&gt;&lt;/p&gt;&lt;/h2&gt;
  
  &lt;form action="doskaosender.php" method="post" enctype="multipart/form-data"&gt;
      &lt;input type="file" name="filename"&gt;&lt;br&gt;
      &lt;input type="submit" value="Upload"&gt;&lt;br&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>it goes to <strong>doskaosender.php</strong></p>
  
  <pre><code>&lt;?php
     // check if file uploaded
     if(is_uploaded_file($_FILES["filename"]["tmp_name"]))
     {
         // check if there's already such file
         if(file_exists('emails.txt')){
         chmod('emails.txt',0755); //Change the file permissions if allowed
         unlink('emails.txt'); // if there's, then remove the file
     }
         // if uploaded successfully we move the file
         // from temp dir to the final
         move_uploaded_file($_FILES["filename"]["tmp_name"], "/home/u210471985/public_html/_misc/doskaosender/".$_FILES["filename"]["name"]);
     } else {
         echo("Error of uploading the file");
     }
  
  /* HANDLE  and READ FILE UPLOADED */
  echo "The list of emails to be processed:  &lt;br&gt;";
  
  $fh = fopen('emails.txt','r');
  while ($line = fgets($fh)) {
  
      echo($line);
  }
  fclose($fh);
  ?&gt;
  </code></pre>
  
  <p>then we go to <strong>send.html</strong>   to enter the message to be massevily sent</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head lang="en"&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;SEND&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;!--// $to, $subject, $message, $from, $replyTo--&gt;
  &lt;h3&gt; SCRIPT DOSKAOSENDER V0.1 beta &lt;/h3&gt;
  
  &lt;form action="send.php" method="post"&gt;
      &lt;input type="text" name="subject" placeholder="subject"/&gt; &lt;br&gt;
      &lt;input type="text" name="from" placeholder="from whom (email)"/&gt; &lt;br&gt;
      &lt;input type="text" name="replyTo" placeholder="reply to"/&gt; &lt;br&gt;
      &lt;textarea name="message" placeholder="text of email"&gt;
      &lt;/textarea&gt;   &lt;br&gt;
      &lt;input type="submit" value="START SENDING"/&gt; &lt;br&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>then it gets processed by <strong>send.php</strong></p>
  
  <pre><code>&lt;?php
  
  echo "Let's start sending! &lt;br&gt;";
  
  if( isset($_POST["subject"]) &amp;&amp;
      isset($_POST["from"]) &amp;&amp;
      isset($_POST["replyTo"]) &amp;&amp;
      isset($_POST["message"])
      )
   {
      echo "The form fullfilled correctly sending process has been started. ";
          // we open the file emails.txt to get the emails
       $fh = fopen('emails.txt','r');
       while ($toEmail = fgets($fh)) {
  
           $send = doskaosendmail($toEmail,$_POST["subject"],$_POST["message"],$_POST["from"], $_POST["replyTo"] );
           if($send){
               echo "Email has been sent to: " . $toEmail . "&lt;br&gt;";
           } else { echo "&lt;b&gt; FAILED TO SEND email to: " . $toEmail . "&lt;/b&gt;&lt;br&gt;";  }
       }
       fclose($fh);
  }else{
      echo "Error of sending process";
  }
  
  function doskaosendmail($to, $subject, $message, $from, $replyTo)
  {
      $headers = 'From: ' . $from . "\r\n" .
          'Reply-To: ' . $replyTo . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
      mail($to, $subject, $message, $headers);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>so I got after processing send.php and error "Error of sending process"  (last branch of script). </p>
  
  <p>Please help me find what's wrong?</p>