how do i send multiple personalized emails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adsegzy
Forum Contributor
Posts: 184
Joined: Tue Jul 28, 2009 9:26 am

how do i send multiple personalized emails

Post by adsegzy »

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;

Code: Select all

<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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how do i send multiple personalized emails

Post by Christopher »

See the manual for the mail() function. There are good examples there:

http://us3.php.net/manual/en/function.mail.php
(#10850)
lunarnet76
Forum Commoner
Posts: 67
Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh

Re: how do i send multiple personalized emails

Post by lunarnet76 »

hi,

use an array with your emails, check http://php.net/manual/en/language.types.array.php

and use

Code: Select all

$emails=array('mike'=>'mike@yahoo.com','bernard'=>'bernard@yahoo.com');
Post Reply