daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Apr 27th, 2016 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. require_once __DIR__.'/vendor/autoload.php';
  3.  
  4. mb_internal_encoding("UTF-8");
  5. mb_language("japanese");
  6.  
  7. $address = fopen('address.csv', 'r');
  8. $mail_body = file_get_contents('MM.html');
  9.  
  10. if ($address){
  11.     while (!feof($address)) {
  12.         $buffer = fgets($address);
  13.         send_mail($buffer, '件名', $mail_body);
  14.     }
  15. }
  16.  
  17. function send_mail($to, $subject, $body) {
  18.  
  19.     $from = "";
  20.     $fromName = "";
  21.  
  22.     $mail = new PHPMailer;
  23.     $mail->CharSet = "iso-2022-jp";
  24.     $mail->Encoding = "7bit";
  25.  
  26.     $mail->isSMTP();
  27.     $mail->SMTPAuth = true;
  28.     $mail->Host = "smtp.sendgrid.net:587";
  29.     $mail->Username = "";
  30.     $mail->Password = "";
  31.  
  32.     $mail->AddAddress($to);
  33.     $mail->From = $from;
  34.     $mail->FromName = mb_encode_mimeheader(mb_convert_encoding($fromName, "jis", "utf-8"));
  35.     $mail->Subject = mb_encode_mimeheader(mb_convert_encoding($subject, "jis", "utf-8"));
  36.     $mail->Body = mb_convert_encoding($body, "jis", "utf-8");
  37.     $mail->isHTML(true);
  38.  
  39.     $status = "OK";
  40.  
  41.     if (!$mail->Send()) {
  42.         $status = "ERROR";
  43.     }
  44.  
  45.     $fo = fopen("mail_log_".date('Ym').".log", "a");
  46.     fwrite($fo, "\n--------------------------------------------------\n");
  47.     fwrite($fo, "status: " . $status . "\n");
  48.     fwrite($fo, date('Y-m-d H:i:s')."\n");
  49.     fwrite($fo, $subject."\n\n");
  50.     fwrite($fo, $body."\n");
  51.     fclose($fo);
  52.  
  53.     if ($status == "OK") {
  54.         return true;
  55.     } else {
  56.         return false;
  57.     }
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top