email script

Code:
<?php

$email_file = "/path/to/emails.txt"

$subject    = "subject";
$message    = "message body";
$headers    = "From: [email protected]";

$emails = explode("\n", file_get_contents($email_file));

foreach($emails as $to) {
  echo "Emailing $to ... ";
  mail(trim($to), $subject, $message, $headers);
  echo "done\n";
}

?>
Not tested, but it should work fine. See http://php.net/mail for extra options for mail(). $to is trim()ed because Windows is gay and uses \r\n for newlines. You could also preg_split("/\r?\n/", file_get_contents($email_file)) and you wouldn't have to trim() $to.
 
Code:
<?php
$h = fopen("mails.txt", "r");
if($h)
{
 while(($mail = fgets($handle)) !== false)
 {
  $mail = trim($mail);
  print mail($mail, 'Message subject', 'Message body') ? "$mail - ok<br />" : "$mail - err<br />";
  ob_flush();
  flush();
 }
 fclose($h);
}
?>
 
Code:
<?php

$email_file = "/path/to/emails.txt"

$subject    = "subject";
$message    = "message body";
$headers    = "From: [email protected]";

$emails = explode("\n", file_get_contents($email_file));

foreach($emails as $to) {
  echo "Emailing $to ... ";
  mail(trim($to), $subject, $message, $headers);
  echo "done\n";
}

?>
Not tested, but it should work fine. See http://php.net/mail for extra options for mail(). $to is trim()ed because Windows is gay and uses \r\n for newlines. You could also preg_split("/\r?\n/", file_get_contents($email_file)) and you wouldn't have to trim() $to.
thanks a lot!
PHP:
$email_file = "/path/to/emails.txt";
btw you forgot the ;
 
I think fopen("mails.txt", "r"); is not the right way to get mail text, you can use classes for it or you can include file to get mail text.
 
Research Pear PHP mailing class, thats more advanced and you can use SMTP.
 
Try phpmailer with smtp auth
For opening large e-mail lists use:
Code:
$file_handle = fopen("mailfile", "r");
while (!feof($file_handle)) {
   $mail = fgets($file_handle);
echo $mail;
}
my 1st post btw :P
 
Last edited:
Back
Top