/** * メールを送信する * 参考:http://doremi.s206.xrea.com/zend/ref/zend_mail.html * @param string $from 送信元のメールアドレス * @param string $to 送信先のメールアドレス * @param string $subject メールの表題 * @param string $body メールの内容 * @param string $form_label 重要度フラグなど * @return void */ public static function send($from, $to, $subject, $body, $from_label = '') { global $smtp_server; // mb_encode_mimeheader挙動にかかわる大事な指定 mb_internal_encoding('JIS'); $mail = new Mail('ISO-2022-JP'); // 送信元および、名前 $mail->setFrom($from, mb_encode_mimeheader(self::to_jis($from_label), 'JIS', 'B')); // 送信先 $mail->addTo($to); // 長すぎる日本語件名を分割する $mail->setSubject(preg_replace('/\\s+/', ' ', mb_encode_mimeheader(self::to_jis($subject), 'JIS', 'B'))); // 返信先を自分に $mail->setReplyTo($from); // メールの内容 $mail->setBodyText(self::to_jis($body), "ISO-2022-JP", Mime::ENCODING_7BIT); // エンコード $mail->setHeaderEncoding(Mime::ENCODING_BASE64); // 本文の文字コード $mail->addHeader('Content-Type', 'text/plain; charset=iso-2022-jp'); // エラーなら自分に(不要ですが) $mail->addHeader('Errors-to', $from); // 先頭ビット使ってません $mail->addHeader('Content-Transfer-Encoding', '7bit'); // メール送信者 $mail->addHeader('X-Mailer', S_APPNAME . ' ' . S_VERSION); // STMPサーバーが指定されていない場合Sendmailでメールを送る if (empty($stmp_server)) { // "-fメアド"でReturn-Path設定 $mail->send(new Sendmail('-f{' . $notify_from . '}')); } else { $mail->send(new Stmp($smtp_server)); } unset($mail); }
$to = $emailsArray[$sender]; //$body = "Hi,\n\nHow are you?"; $headers = array('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = new Mail\Message(); $mail->setBody('This is the text of the email.'); $mail->setFrom('*****@*****.**', 'Sender\'s name'); $mail->addTo('*****@*****.**', 'Name of recipient'); $mail->setSubject('TestSubject'); $transport = new Mail\Transport\Sendmail(); $transport->send($mail); //$mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo "<p>" . $mail->getMessage() . "</p>\n"; } else { echo "<p>Message successfully sent to {$to}</p>\n"; } } $to = $emailsArray['Joe']; $body = "Hi Mom,\n\nCarol has decided that we should have a 'Master' list just incase someone forgets who their suppose to get a gift for, so heres the list\n"; foreach ($completedList as $sender => $receiver) { $body = $body . "\n" . $sender . " is getting a gift for " . $receiver; } $headers = array('From' => $from, 'To' => $to, 'Subject' => 'Master List'); $smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo "<p>" . $mail->getMessage() . "</p>\n"; } else { echo "<p>Message successfully sent to {$to}</p>\n"; }