畢竟, gmail 是很好用的 mailer ,所以我的 solution 就是!! (自動背景配樂!~)
少林功夫加唱歌跳舞! ♬
... 冷掉了
#!/usr/bin/php -q
<?
function body_get_receiver($body)
{
$cols = explode("\n", $body);
for ($i = 0; $i < keyword =" substr($cols[$i]," keyword ="="" keyword ="="" ans =" strstr($cols[$i]," ans =" substr($ans," i =" 0;" ans =" substr($ans," cols =" explode(" to_name="$cols[0];" body = "" i="0;" subject =" $argv[$i+1];" fn="php://stdin" body="" fs="fopen($fn," to_address =" ($argv[1])" fs =" fopen(" attach = "" mail =" new">IsSMTP(); // set mailer to use SMTP
$mail->CharSet = "utf8";
$mail->Encoding = "base64";
$mail->From = "anton.tw@gmail.com";
$mail->FromName = "anton";
$mail->Username = "帳號@gmail.com";
$mail->Password = "密碼";
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465; //default is 25, gmail is 465 or 587
$mail->SMTPAuth = true;
$mail->addAddress($to_address, $to_name);
$mail->WordWrap = 50;
if (!empty($attach))
$mail->AddAttachment($attach);
$mail->IsHTML(false);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send())
{
echo "郵件送出失敗! ";
echo "錯誤訊息: " . $mail->ErrorInfo . " \n";
return false;
}
else
{
echo("寄信 $attach 給 $to_name <$to_address> 完成! \n");
return true;
}
}
?>
使用方式,就是
echo "test" | mail xxx@gmail.com -s "subject"
裡面的 body_get_receiver 這個 function 是特別為了 mediawiki 生的。因為 mediawiki 的收信人是直接 pipe 在 mail body 裡面的,所以沒辦法知道收信人是誰的時候,就從 body 裡面拉出來,就好了。(其實還有不少例外沒處理,不過,管它的~ 我起個頭而已,後面有人想玩就接著玩唄~)
沒有留言:
張貼留言