実際、PHP の mail() で送信できます。少しトリッキーで、「送信元」アドレスの代わりにヘッダーを使用する必要があります。SMS プロバイダーを持っている方が良いですが、この方法は機能します。
メールを送信するコード:
$sms_gateways = file_get_contents('sms_gateways.txt'); //SMS gateways (see txt file below)
$tmp = split("\n", $sms_gateways); //parse gateways file
$SMS_GATEWAYS = array();
for ($i=0; $i<count($tmp); $i++) {
$itm = split(",", $tmp[$i]); //parse title/format
$SMS_GATEWAYS[$itm[0]] = $itm[1]; //add # format to array
}
$eol = "\n"; //varies between Linux/Mac/Windows End Of Line...usually \n
$headers = 'From: SMS <sms@mywebsite.com>'.$eol;
$headers .= 'Reply-To: SMS <sms@mywebsite.com>'.$eol;
$headers .= 'Return-Path: SMS <sms@mywebsite.com>'.$eol;
$headers .= "Message-ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: text/plain; boundary=\"".$mime_boundary."\"".$eol;
$phone = '8005551212'; //target phone # (do not use any symbols or spaces)
//get A/B/C pieces in phone #:
$phone_a = substr($phone, 0, 3);
$phone_b = substr($phone, 3, 3);
$phone_c = substr($phone, 6, 4);
//assemble gateways emails:
foreach ($SMS_GATEWAYS as $key => $val) {
$email_str = str_replace("#a", $phone_a, str_replace("#b", $phone_b, str_replace("#c", $phone_c, $val)));
if (mail($email_str, "", $sms_txt, $headers)) {
//echo "success sending to $email_str<br>\r\n";
$sms_success_count++;
} else {
$sms_fail_count++;
}
}
sms_gateways.txt ファイル:
Alaska Communications Systems,#a#b#c@msg.acsalaska.com
Alltell Wireless,#a#b#c@message.alltel.com
AT&T Wireless (1),#a#b#c@txt.att.net
Bell Canada,#a#b#c@txt.bell.ca
Boost Mobile,#a#b#c@myboostmobile.com
Cellular One (Dobson),#a#b#c@mobile.celloneusa.com
Cellular South,#a#b#c@csouth1.com
Centennial Wireless,#a#b#c@cwemail.com
Cincinnati Bell,#a#b#c@gocbw.com
Cingular (Postpaid),#a#b#c@cingular.com
Cingular (Prepaid),#a#b#c@cingulartext.com
Cricket,#a#b#c@sms.mycricket.com
Koodo Mobile and Telus Mobnility,#a#b#c@msg.telus.com
MetroPCS,#a#b#c@mymetropcs.com
MTS Mobility,#a#b#c@text.mtsmobility.com
Nextel,#a#b#c@messaging.nextel.com
Pioneer Cellular,#a-#b-#c@zsend.com
Pocket Wireless,#a#b#c@sms.pocket.com
PC Telecom,#a#b#c@mobiletxt.ca
Qwest Wireless,#a#b#c@qwestmp.com
Rogers Wireless,#a#b#c@pcs.rogers.com
SaskTel,#a#b#c@sms.sasktel.com
South Central Communications,#a#b#c@rinasms.com
Sprint(PCS),#a#b#c@messaging.sprintpcs.com
Sprint(Nextel),#a#b#c@page.nextel.com
Straight Talk,#a#b#c@vtext.com
Syringa Wireless,#a#b#c@rinasms.com
T-Mobile (USA),#a#b#c@tmomail.net
Unicel,#a#b#c@utext.com
US Cellular (USA),#a#b#c@email.uscc.net
Verizon (USA),#a#b#c@vtext.com
Viaero (USA),#a#b#c@viaerosms.com
Virgin Mobile (CA),#a#b#c@vmobile.ca
Virgin Mobile (USA),#a#b#c@vmobl.com
この方法では、リスト内のすべての通信事業者に電子メールが送信されますが、実際に受信されるのはそのうちの 1 つだけです (2 つの通信事業者が同じ電話番号を使用することはないため)。これにより、サーバーがスパム ブラックリストに登録される可能性がありますが、定期的に問題が発生することはありません。
さらに注意: ゲートウェイのテキスト ファイルで #a#b#c を使用する理由は、一部のゲートウェイでは市外局番/プレフィックス/サフィックスの形式が異なるためです。つまり、"#a-#b-#c@whatever.com "