Use PHP to send a timed SMS instance _php instance free of charge

Source: Internet
Author: User
Tags error code php script

Because there is no development platform, the existing APIs are Third-party development, seemingly by cracking WAP flying or 3G flying, simulate the behavior of the browser to send text messages. In addition, Google Code has open source PHP fly Letter Send class php-fetion. These fly-through interface facilitates the development of timed SMS.

background: mom is old, not highly educated, but need to know the weather information every day to work in the fields, and can not get the weather through the network, only through television. So I thought about crawling the weather information on the Internet and sending it to my mother by SMS.

problem: It is not possible to send the weather message to my mother every day, the existing weather forecast to subscribe to SMS is Money.

Solve:

Send SMS to mobile phone for free

Scenario 1: Using the fly-through API

Because there is no development platform, the existing APIs are Third-party development, seemingly by cracking WAP flying or 3G flying, simulate the behavior of the browser to send text messages. In addition, Google Code has open source PHP fly Letter Send class Php-fetion (http://code.google.com/p/php-fetion/). These fly-through interface facilitates the development of timed SMS.

The only drawback is that the Third-party API is not stable, but also the risk of flying letter account leakage.

Here, I use http://3.ibtf.sinaapp.com/provided by the Flying Letter API to send text messages.

The API simply provides the sender's cell phone number, the password, the recipient's cell phone number, and the message content as a URL parameter. The only attention is the Chinese garbled problem (using GBK instead of UTF-8 encoding, direct input Chinese garbled, input Chinese GBK code phone to receive normal), you can use the Iconv function or add parameters "&u=1" to solve.

Option 2: Use the SMS alert function of 139 mailboxes

139 mailbox is also a mobile business in China, providing the function of email message reminder. As long as the mail in the mailbox to set up the arrival of the notification OK, in addition to MMS, other letters, ordinary text messages, hands-free text messages are available. Note that time is long, the Outbox and Inbox should be cleared, so as not to occupy too much space and affect the normal use.

In addition, you only need to write a Simple mail-sent PHP script. And the Sina SAE also provides this mail service. Using the functions in mail service, you can quickly send mail with the following code:

<?php 
$mail = new Saemail (); 
$ret = $mail->quicksend (  
' recipient @139.com ',  
' This is the subject ', 
' This is the text ', 
' This is the sender's mailbox ',  
' This is the sender's password ', 
' This is the SMTP Service host ',  
[This is the SMPT service port]];  
Output error code and error message 
if ($ret = = False) 
Var_dump ($mail->errno (), $mail->errmsg ()) when sending fails; 
? > 

The effect is as follows:

After the message is sent successfully, it needs to be timed. Fortunately, the Sina SAE provides a cron service. The cron service is a distributed, timed service provided by the SAE for developers to periodically trigger specific actions of the developer to meet the needs of such as the timing list. Cron settings are implemented through the app's Config.yaml, and as long as the user is configured in the Config.yaml in the app directory according to our provided syntax format, it will take effect after deployment.

Add cron

Edit Saetest/1/config.yaml, add cron segments, Config.yaml examples are as follows:

Name:saetest
Version:1
Cron:
-Description:cron Test
url:mycron/test.php
Schedule: $ Day of October 19:00
Timezone:beijing
-Description:another cron Test
url:mycron/another_test.php
Schedule:every mins
Timezone:beijing

The above example describes two timed tasks: mycron/test.php every October 2 19 o'clock, performing mycron/another_test.php every 10 minutes

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.