Source language: Translate to:

Send email & Recover data[PHP Tutorial]

Questions and information about creating Internet aware NeoBook applications. Including PHP, HTML, FTP, HTTP, Email, etc.

Moderator: Neosoft Support

Send email & Recover data[PHP Tutorial]

Postby smartmedia » Tue Nov 24, 2009 2:29 am

Hi..

This is a script a made to send email as response to a lost password:

First steps:

1) Your server Windows or Linux must support PHP 4 or 5 version
2) Your server must support SMTP (Simple Mail Transfer Protocol)
3) Optionally your server must support MySQL or other database

Now, let say that we want to send from our application the lost password to user. Make sure you are using a MySQL or similar database to server,
then create a pub and connect to database.
Create a CustomWindow from NB like the one shown in photo
Image

Then we need to create a PHP that will respond to PUB call and send the email.

You can download all the code from here: http://rapidshare.com/files/311450396/PHP_-_Lost_Password.rar
Now let's explain few thinks.
The logic behind this, is simple. In order to send the lost password to user, first we must authenticate him. In order to do that we using a SELECT. So, if there is a record in our database with the same username and email, we pass the appropriate data (email - username - password) to InternetPost NB command. How...???
PHP accept data using POST method, so we enter in Data to post to server the following To= Username= PassKey=
If you have more than 1 data to post to server make sure you enter & after the first data, like this: To= &Username= &PassKey=
Now, after the = symbol you enter the variables contain the data. Something like this: To=[Database.Users.email]&Username=[Database.Users.Username]&PassKey=[Database.Users.Password]
In the part NB evolves, you done. Let's go to server side and see the PHP script.

In the PHP we use the function mail() This functions has 4 Arguments separated by comma. 1) The receiver email 2) Subject of email 3) The message 4) The email headers
Like this: mail($To, $Subject, $MESSAGE, $EMAIL_HEADER);
If you check the PHP example you see that we set 3 mail headers, From: - Reply-to: - Content-type: The first one say who send the message, the second who to reply, and third says that, the contains of the email is HTML.
Now check in the code and you will see the 3 arguments we set in InternetPost in NB. $To $Username $PassKey Dollar symbol $ in front of name says that this is a variable. Make sure that you write exactly because for PHP $name and $Name are 2 different variables.
Now inside $MESSAGE variable you can add your HTML code who will send it to user. If you don't want to send the email as HTML just remove the $EMAIL_HEADER .= "Content-type: text/html; charset=ISO-8859-1\n"; line.
You done, upload the PHP script in your server. Modify the pub, run it, and you will receive the email.
User avatar
smartmedia
 
Posts: 889
Joined: Fri Apr 01, 2005 6:50 am
Location: Hellas

Return to NeoBook and the Internet

Who is online

Users browsing this forum: No registered users and 1 guest

cron