PHP mass sending email script
03:08 15 Jun 2015

I'm trying to make email mass sender for our users in small local classifieds site.

Idea is: I use upload.html to upload emails.txt file with list of emails, separated on each line

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 which takes subject, from, replyTo and message and sends single email.

Then I just loop the reading of email.txt, take each line by line and pass the email to single sender doskaosendmail function.

But I got an error in send.php, something goes wrong, and I can't put my finger on what exactly.

The code.

upload.html

    


    
    Upload Emails


UPLOAD emails.txt file



it goes to doskaosender.php

";

$fh = fopen('emails.txt','r');
while ($line = fgets($fh)) {
    
    echo($line);
}
fclose($fh);
?>

then we go to send.html to enter the message to be massively sent




    
    SEND



SCRIPT DOSKAOSENDER V0.1 beta






then it gets processed by send.php

";

if( isset($_POST["subject"]) &&
    isset($_POST["from"]) &&
    isset($_POST["replyTo"]) &&
    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 . "
"; } else { echo " FAILED TO SEND email to: " . $toEmail . "
"; } } 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); } ?>

so I got after processing send.php and error "Error of sending process" (last branch of script).

Please help me find what's wrong?

php email