Hello Fellas,
Am designing a sign and there is a page (INVITE FRIENDS) where members can invite there friends. All the member has to do is just to enter the friends name and email into the form and click invite. the form is below;

<form id="form1" name="form1" method="post" action="<?php echo $_SESSION['PHP_SELF']; ?>">
            <table width="500" border="0" align="center" cellpadding="5" cellspacing="0">
              <tr>
                <th width="26" scope="col" id="heading4"><div align="center"></div></th>
                <th width="182" scope="col" id="heading4"><div align="left">                  Names</div></th>
                <th width="262" scope="col" id="heading4"><div align="left">                  Email Addresses </div></th>
              </tr>
              <tr>
                <td class="style5"><div align="center">1.</div></td>
                <td class="style5"><label>
                  <input name="name1" type="text" id="name1" />
                </label></td>
                <td class="style5"><label>
                  <input name="email1" type="text" id="email1" size="40" />
                </label></td>
              </tr>
              <tr>
                <td><div align="center">2.</div></td>
                <td><input name="name2" type="text" id="name2" /></td>
                <td><input name="email2" type="text" id="email2" size="40" /></td>
              </tr>
              <tr>
                <td class="style5"><div align="center">3.</div></td>
                <td class="style5"><input name="name3" type="text" id="name3" /></td>
                <td class="style5"><input name="email3" type="text" id="email3" size="40" /></td>
              </tr>
              <tr>
                <td><div align="center">4.</div></td>
                <td><input name="name4" type="text" id="name4" /></td>
                <td><input name="email4" type="text" id="email4" size="40" /></td>
              </tr>
              <tr>
                <td class="style5"><div align="center">5.</div></td>
                <td class="style5"><input name="name5" type="text" id="name5" /></td>
                <td class="style5"><input name="email5" type="text" id="email5" size="40" /></td>
              </tr>
            </table>
                    <p align="center">
                      <input type="submit" name="Submit" value="Invite Friends" />
                    </p>
          </form>

assuming a member named Felix entered filled the form as below;

1. Mike (mike@yahoo.com)
2. Bond (bond@gmail.com)
3. Benita (benita@hotmail.com)
4. Oliver (oliver@yahoo.co.uk)
5. Annabel (annabel@hotmail.com)

The message is like this;

From: http://www.mysite.com
To: [friend's email]
Hello [Friend's Name]
Your friend Felix found our site interesting and want you to check it out. etc

I know I can use MAIL($to, $subject, $message, $header)
The problem is that, how do i make the message to go to each email and echo the name of the email owner? Eg,

From: http://www.mysite.com
To: mike@yahoo.com
Hello Mike
Your friend Felix found our site interesting and want you to check it out. etc

From: http://www.mysite.com
To: bond@gmail.com
Hello Bond
Your friend Felix found our site interesting and want you to check it out. etc

From: http://www.mysite.com
To: benita@hotmail.com
Hello Benita
Your friend Felix found our site interesting and want you to check it out. etc

From: http://www.mysite.com
To: oliver@yahoo.co.uk
Hello Oliver
Your friend Felix found our site interesting and want you to check it out. etc

From: http://www.mysite.com
To: annabel@hotmail.com
Hello Annabel
Your friend Felix found our site interesting and want you to check it out. etc

Please help
Regards

u need to use a while loop to iterate through the entries performing the mail function until there are no more emails present

One way to get that done may be to include the author in the $subject var.

$subject = $author . ': '. $realsubject
Member Avatar for diafol

You can send via BCC (blind carbon copy) if sending a batch mail - you really shouldn't send other people's details to every recipient.

However, if you want to personalise with "Hi John" or whatever, you'll need to use a loop, sending individual mails.

pseudocode:
validate names and addresses
place name and addresses into an array
get email subject and body (from DB or text file?)
start loop (end when no of recipient reached)
extract name and address - place into headers
substitute name into body (to personalise)
send mail
check send status - if OK - enter email id/address/name/datetime into DB?
On fail - do something else - eg. data into log table or just display 'failed' etc.
end loop

hey bee

do the following

your form is like

<form id="form1" name="form1" method="post" action="mailTO.php">
            <table width="500" border="0" align="center" cellpadding="5" cellspacing="0">
              <tr>
                <th width="26" scope="col" id="heading4"><div align="center"></div></th>
                <th width="182" scope="col" id="heading4"><div align="left">                  Names</div></th>
                <th width="262" scope="col" id="heading4"><div align="left">                  Email Addresses </div></th>
              </tr>
              <tr>
                <td class="style5"><div align="center">1.</div></td>
                <td class="style5"><label>
                  <input name="name[]" type="text" id="name[]" />
                </label></td>
                <td class="style5"><label>
                  <input name="email[]" type="text" id="email[]" size="40" />
                </label></td>
              </tr>
              <tr>
                <td><div align="center">2.</div></td>
                <td><input name="name[]" type="text" id="name[]" /></td>
                <td><input name="email[]" type="text" id="email[]" size="40" /></td>
              </tr>
              <tr>
                <td class="style5"><div align="center">3.</div></td>
                <td class="style5"><input name="name[]" type="text" id="name[]" /></td>
                <td class="style5"><input name="email[]" type="text" id="email[]" size="40" /></td>
              </tr>
              <tr>
                <td><div align="center">4.</div></td>
                <td><input name="name[]" type="text" id="name[]" /></td>
                <td><input name="email[]" type="text" id="email[]" size="40" /></td>
              </tr>
              <tr>
                <td class="style5"><div align="center">5.</div></td>
                <td class="style5"><input name="name[]" type="text" id="name[]" /></td>
                <td class="style5"><input name="email[]" type="text" id="email[]" size="40" /></td>
              </tr>
            </table>
                    <p align="center">
                      <input type="submit" name="Submit" value="Invite Friends" />
                    </p>
          </form>

okay

now mailTO.php

<?
$em = $_POST['email'];
$i = 0;
foreach($_POST['name'] as $value){
	// your friend name is $value
	$i = $i +1;
	mail($em[$i], 'your subject', 'your message', 'header');
}
?>

have fun :)

Member Avatar for diafol
<?
$em = $_POST['email'];
$i = 0;
foreach($_POST['name'] as $value){
// your friend name is $value
$i = $i +1;
mail($em[$i], 'your subject', 'your message', 'header');
}
?>

Sorry to pick at the above, BUT

*short tags - use proper php tags
*no POST value validation
*no error capture - user has no idea if email was sent successfully - or at worst, will get the horrible php error.

Remember your message requires the names of both 'inviter' and receipient. I purposely didn't give code as you'd be better off developing it yourself - you weren't far off.

hey we will give the idea only man

you have to validate the user input and short tags error capturing okay.... :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.