Emailing members of a forum

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tutu saint
    New Member
    • Jun 2011
    • 21

    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.


    Code:
    <?php
    //define the receiver of the email
    $to = 'youraddress@example.com';
    //define the subject of the email
    $subject = 'Test email'; 
    //define the message to be sent. Each line should be separated with \n
    $message = "Hello World!\n\nThis is my first mail."; 
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
    //send the email
    $mail_sent = @mail( $to, $subject, $message,$serder, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You haven't said what problem you're running into.

    Comment

    • tutu saint
      New Member
      • Jun 2011
      • 21

      #3
      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.

      Comment

      • Niheel
        Recognized Expert Moderator Top Contributor
        • Jul 2005
        • 2433

        #4
        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_ar ray to to loop through your view.

        More information with examples can be found at:
        Fetch the next row of a result set as an associative, a numeric array, or both
        niheel @ bytes

        Comment

        • tutu saint
          New Member
          • Jun 2011
          • 21

          #5
          Thanks Niheel,
          I am still very new in php and can implement this but with time. can you help me with a sample code?

          Comment

          • Niheel
            Recognized Expert Moderator Top Contributor
            • Jul 2005
            • 2433

            #6
            Take a look at the following example on php.net
            Fetch the next row of a result set as an associative, a numeric array, or both


            Code:
            $result = mysqli_query($link, "select * from user");
            while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
             // place code for email
             // make sure you assign the proper variables.
            
            }
            niheel @ bytes

            Comment

            • computerfox
              Contributor
              • Mar 2010
              • 276

              #7
              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....

              Comment

              • Murat Bastas
                New Member
                • Jul 2012
                • 25

                #8
                mail function is works like example:
                Code:
                mail('mail1@domain1.com,mail2@domain2.com,mail3@domain3.com', $subject, $message, $headers);

                Comment

                • tutu saint
                  New Member
                  • Jun 2011
                  • 21

                  #9
                  Niheel's link was very helpful and i was able to get the below codes working
                  Code:
                    $allemails="select email from members";
                    //mysql_select_db($database_dbCon, $dbCon);
                    mysql_select_db($database,$db_connect) or die( "Unable to select database");
                    $Result = mysql_query($allemails, $db_connect) or die(mysql_error());
                   
                  //  $str="";
                    while($row=mysql_fetch_array($Result)){
                    
                     $to=$row[0];
                  $sender="<gospel@domain.com>";
                  // Your subject
                  $subject="Gospel Alert from domain.com";
                  
                  // From
                  $header="from: Gospel Alart <news@domain.com>";
                  
                  // Your message
                  $messages= "Your daily news alert  has returned the following alert for you today\r\n";
                  //$messages= "<a href=http://alart1.php</a><br>";
                  // send email
                  $sentmail = mail($to,$subject,$messages,$header);	
                    //$str.="-".$sentmail;
                    if($sentmail)
                    echo("Mail sent to ".$row[0]." successfully<br/>");
                    else
                    echo("Mail not delivered to ".$row[0]." successfully<br/>");
                    }
                  But these mail are not being delivered to my email. Please what could be the cause

                  Comment

                  • Murat Bastas
                    New Member
                    • Jul 2012
                    • 25

                    #10
                    you did start new topic, i did answer in your new topic

                    Comment

                    Working...