プログラムブログ

PHP、Database、ネットワーク、サーバセキュリティ

添付ファイルつきメールをpearを利用して送信

Pearの addAttachment() を利用すると比較的楽に添付ファイル付きメールをプログラムから送信できる。

例.
< ?php

require_once (”Mail.php”);
require_once (”Mail/mime.php”);

$message = “”;
$message .= “添付ファイルつきメール\n”;
$message = mb_convert_encoding($message,”ISO-2022-JP”,”EUC-JP”);

$mime = new Mail_mime(”\n”);
$mime->setTxtBody($message);
$attachment = “test1.txt”;
$mime->addAttachment($attachment);

$build_param = array(
“text_charset” => “ISO-2022-JP”,
“head_charset” => “ISO-2022-JP”
);
$body = $mime->get( $build_param );

#メール送信
$params=array(
“host”=>”localhost”,
“port”=>25,
“auth”=>FALSE);

$headers=array(
“From”=>mb_encode_mimeheader(”send_cron”,”ISO-2022-JP”).
“”,
“Subject”=>mb_encode_mimeheader(”添付ファイルテスト”,”ISO-2022-JP”),
“Content-Type”=>”text/plain; charset=ISO-2022-JP”,
“Content-Transfer-Encoding”=>”7bit”
);

$hdrs = $mime->headers($headers);

$mail = Mail::factory(’mail’);
$mail->send(”test@test.com”,$hdrs,$body);

?>

No comments yet. Be the first.

Leave a reply