Publishing System Settings Logout Login Register
Create an Invitation Script
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on March 10th, 2007
9834 views
PHP Coding
In this tutorial on how to make an "Invite your freinds" Box just like the one on this site. To begin with you need to create a the form in which your users will

 <form name="FRIENDEMAIL" method="post" action="">
<strong>Your name:</strong>
<input name="name" type="text">
<label><br>
<strong>Emails:</strong>
<textarea name="email" cols="15" rows="3" id="email"></textarea>
</label>
<br>
<label>
<input type="submit" name="freind" value="Invite a freind!">
</label>
</form>


Then you have the phpcode


if($_POST['freind']){
$emails = $_POST['email'];
$email = explode(",",$emails);
$emailcount = count($email);
$inviter = $_POST['name'];
$message = "YOUR MESSAGE HERE! ";
$i = 0;
while ($i < $emailcount){
$emailto = $email[$i];
mail("$emailto","YOURSITE Invites you!",$message , "From: [email protected] ");
$i = $i + 1;
}}



Firstly we need to split up the email addresses. We use the explode function to do this.

$email = explode(",",$emails);


Then we need to count how many variables are in the array. We use the count function for this.

[code]$message = "[b]YOUR MESSAGE HERE![b] ";[/code]

You will want to change the message that is send out. Now we are going to go the iteration (loop) so that the emails are sent.


$i = 0;
while ($i < $emailcount){
$emailto = $email[$i];
mail("$emailto","YOURSITE Invites you!",$message , "From: [email protected] ");
$i = $i + 1;


We start by setting the variable $i = 0 outside the loop and then the loop starts. Im using a while command to loop the emails sent out. The mail function is quite simple.

mail('to','Subject','Message','Additional headers');

Thats about it

Arutha
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Arutha

As much as i love the default message i want to just say hello and to tell you to visit my blog :)
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top