473,386 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Emailing members of a forum

I have a registration form which sends confirmation email to the new user. i also want the same email to be sent to all registered users.

I have a view containing all registered members email and i need to inform all of them of the new user.

This is what i have so far and i need help in achieving this.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. //define the receiver of the email
  4. $to = 'youraddress@example.com';
  5. //define the subject of the email
  6. $subject = 'Test email'; 
  7. //define the message to be sent. Each line should be separated with \n
  8. $message = "Hello World!\n\nThis is my first mail."; 
  9. //define the headers we want passed. Note that they are separated with \r\n
  10. $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
  11. //send the email
  12. $mail_sent = @mail( $to, $subject, $message,$serder, $headers );
  13. //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
  14. echo $mail_sent ? "Mail sent" : "Mail failed";
  15. ?>
  16.  
  17.  
Jul 26 '12 #1
9 1948
Rabbit
12,516 Expert Mod 8TB
You haven't said what problem you're running into.
Jul 26 '12 #2
I want to send a mail informing all registered members of the new members registration. I wan every registered member to receive the email informing them of a new user.
Jul 26 '12 #3
Niheel
2,460 Expert Mod 2GB
Tutu, you have the code to send an email. Now you have to take the view that lists all your members assign it to an array and loop through it. You can create a function using the code and then call it or you could just place that code inside your loop.

If your view of all the registered members is in mysql then you could use the function mysqli_fetch_array to to loop through your view.

More information with examples can be found at:
http://www.php.net/manual/en/mysqli-...etch-array.php
Jul 26 '12 #4
Thanks Niheel,
I am still very new in php and can implement this but with time. can you help me with a sample code?
Jul 26 '12 #5
Niheel
2,460 Expert Mod 2GB
Take a look at the following example on php.net
http://www.php.net/manual/en/mysqli-...ray.php#104189

Expand|Select|Wrap|Line Numbers
  1. $result = mysqli_query($link, "select * from user");
  2. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  3.  // place code for email
  4.  // make sure you assign the proper variables.
  5.  
  6. }
  7.  
Jul 26 '12 #6
computerfox
276 100+
I wouldn't suggest sending EVERYONE a copy because let's say 100 people join in one day.... I know I wouldn't want to get 100 PM's that a new member has joined. Maybe admins, but not normal users....
Jul 30 '12 #7
mail function is works like example:
Expand|Select|Wrap|Line Numbers
  1. mail('mail1@domain1.com,mail2@domain2.com,mail3@domain3.com', $subject, $message, $headers);
Jul 30 '12 #8
Niheel's link was very helpful and i was able to get the below codes working
Expand|Select|Wrap|Line Numbers
  1.  
  2.   $allemails="select email from members";
  3.   //mysql_select_db($database_dbCon, $dbCon);
  4.   mysql_select_db($database,$db_connect) or die( "Unable to select database");
  5.   $Result = mysql_query($allemails, $db_connect) or die(mysql_error());
  6.  
  7. //  $str="";
  8.   while($row=mysql_fetch_array($Result)){
  9.  
  10.    $to=$row[0];
  11. $sender="<gospel@domain.com>";
  12. // Your subject
  13. $subject="Gospel Alert from domain.com";
  14.  
  15. // From
  16. $header="from: Gospel Alart <news@domain.com>";
  17.  
  18. // Your message
  19. $messages= "Your daily news alert  has returned the following alert for you today\r\n";
  20. //$messages= "<a href=http://alart1.php</a><br>";
  21. // send email
  22. $sentmail = mail($to,$subject,$messages,$header);    
  23.   //$str.="-".$sentmail;
  24.   if($sentmail)
  25.   echo("Mail sent to ".$row[0]." successfully<br/>");
  26.   else
  27.   echo("Mail not delivered to ".$row[0]." successfully<br/>");
  28.   }
  29.  
  30.  
But these mail are not being delivered to my email. Please what could be the cause
Jul 30 '12 #9
you did start new topic, i did answer in your new topic
Jul 30 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: blockhead | last post by:
We are looking for someone to either complete a php forum program or create one for us. There isn't really anything that is available that suits our needs and we have specific wants. If you are...
0
by: Paul Kinsella | last post by:
---------------------------------------------------------------------- NEWS BULLETIN - http://www.companywire.net ---------------------------------------------------------------------- Company...
4
by: Mike Moore | last post by:
What is the best way to launch outlook from an asp.net web page? Can you do this using MAPI or is there a control that you can purchase? We are unable to use SMTP. We use MS Exhange and MAPI...
31
by: DirtySnipe | last post by:
I have created a php form with dynamic drop down boxes in it which pull the options from a database. The boxes work fine and the data gets submitted fine but im having a problem getting the box to...
8
by: marjbell | last post by:
I have a Access database of email addresses that I would like to mass email to customers. Can Access be used through Outlook? or can it just be done with Access? I know it is possible to use...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.