PHP mass sending email script -


i'm trying make email mass sender our users in small local classfieds site.

idea is: use upload.html upload emails.txt file list of emails, separated on each line

after upload.html form gets processed doskaosender.php, reads file , and places in local dir processed in next step. go send.html, enter subject, from, replyto , message , click send, get's processed send.php. in send.php create function doskaosendmail wich takes subject, from, replyto , message , sends single email.

then loop reading of email.txt, take each line line , pass eamil single sender doskaosendmail function.

but got error in send.php, goes wrong, , can't put finger on exactly.

the code.

upload.html

    <!doctype html> <html> <head lang="en">     <meta charset="utf-8">     <title>upload emails</title> </head> <body> <h2><p><b> upload emails.txt file </b></p></h2>  <form action="doskaosender.php" method="post" enctype="multipart/form-data">     <input type="file" name="filename"><br>     <input type="submit" value="upload"><br> </form>  </body> </html> 

it goes doskaosender.php

<?php    // check if file uploaded    if(is_uploaded_file($_files["filename"]["tmp_name"]))    {        // check if there's such file        if(file_exists('emails.txt')){        chmod('emails.txt',0755); //change file permissions if allowed        unlink('emails.txt'); // if there's, remove file    }        // if uploaded move file        // temp dir final        move_uploaded_file($_files["filename"]["tmp_name"], "/home/u210471985/public_html/_misc/doskaosender/".$_files["filename"]["name"]);    } else {        echo("error of uploading file");    }  /* handle  , read file uploaded */ echo "the list of emails processed:  <br>";  $fh = fopen('emails.txt','r'); while ($line = fgets($fh)) {      echo($line); } fclose($fh); ?> 

then go send.html enter message massevily sent

<!doctype html> <html> <head lang="en">     <meta charset="utf-8">     <title>send</title> </head> <body> <!--// $to, $subject, $message, $from, $replyto--> <h3> script doskaosender v0.1 beta </h3>  <form action="send.php" method="post">     <input type="text" name="subject" placeholder="subject"/> <br>     <input type="text" name="from" placeholder="from whom (email)"/> <br>     <input type="text" name="replyto" placeholder="reply to"/> <br>     <textarea name="message" placeholder="text of email">     </textarea>   <br>     <input type="submit" value="start sending"/> <br> </form> </body> </html> 

then gets processed send.php

<?php  echo "let's start sending! <br>";  if( isset($_post["subject"]) &&     isset($_post["from"]) &&     isset($_post["replyto"]) &&     isset($_post["message"])     )  {     echo "the form fullfilled correctly sending process has been started. ";         // open file emails.txt 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 . "<br>";          } else { echo "<b> failed send email to: " . $toemail . "</b><br>";  }      }      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 got after processing send.php , error "error of sending process" (last branch of script).

please me find what's wrong?

your function not return thing why getting error please fix function doskaosendmail

function doskaosendmail($to, $subject, $message, $from, $replyto) {         $headers = 'from: ' . $from . "\r\n" .                 'reply-to: ' . $replyto . "\r\n" .                 'x-mailer: php/' . phpversion();          if (@mail($to, $subject, $message, $headers)) {             return true;         } else {             return false;         }     } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -