Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once __DIR__.'/vendor/autoload.php';
- mb_internal_encoding("UTF-8");
- mb_language("japanese");
- $address = fopen('address.csv', 'r');
- $mail_body = file_get_contents('MM.html');
- if ($address){
- while (!feof($address)) {
- $buffer = fgets($address);
- send_mail($buffer, '件名', $mail_body);
- }
- }
- function send_mail($to, $subject, $body) {
- $from = "";
- $fromName = "";
- $mail = new PHPMailer;
- $mail->CharSet = "iso-2022-jp";
- $mail->Encoding = "7bit";
- $mail->isSMTP();
- $mail->SMTPAuth = true;
- $mail->Host = "smtp.sendgrid.net:587";
- $mail->Username = "";
- $mail->Password = "";
- $mail->AddAddress($to);
- $mail->From = $from;
- $mail->FromName = mb_encode_mimeheader(mb_convert_encoding($fromName, "jis", "utf-8"));
- $mail->Subject = mb_encode_mimeheader(mb_convert_encoding($subject, "jis", "utf-8"));
- $mail->Body = mb_convert_encoding($body, "jis", "utf-8");
- $mail->isHTML(true);
- $status = "OK";
- if (!$mail->Send()) {
- $status = "ERROR";
- }
- $fo = fopen("mail_log_".date('Ym').".log", "a");
- fwrite($fo, "\n--------------------------------------------------\n");
- fwrite($fo, "status: " . $status . "\n");
- fwrite($fo, date('Y-m-d H:i:s')."\n");
- fwrite($fo, $subject."\n\n");
- fwrite($fo, $body."\n");
- fclose($fo);
- if ($status == "OK") {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement