Php mail() code in this situation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Php mail() code in this situation

    Hello, i wud like to send different data(1st store in my db) nd then send, to different users in my database with mail()
    function, can anyone tell me how can i achieve this?
    Example- there are 60 registered members in my site, so for each
    member i wud like to send a unique message, but all at once, so can anyone help me ? Thank u..

    #2
    Hi.

    Like this, just change table names and maybe write a form to add message.

    PHP Code:
    $emails = array(); 
    $select mysql_query('SELECT `email` FROM `users`'); 
    while (
    $sel mysql_fetch_array($select)) { 
        
    $emails[] = $sel[0]; 

    foreach (
    $emails as $email) { 
        
    $subject 'Subject...'
        
    $message 'Message...'
        
    $header 'MIME-Version: 1.0'.PHP_EOL
        
    $header .= 'Content-type: text/html; charset=utf-8'.PHP_EOL
        
    $header .= 'From: mailing@mail.com'
         
        @
    mail($email$subject$message$header); 

    echo 
    'Sent!'

    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    Comment


      #3
      i would recommend making sure the server your on. allows email sending and doesnt limit you to how many emails you send in a certain period of time. as with a function such as this it could be classed as mass mailing. (email bombing) even though going to many different email addresses. its a very quick way to getting your site/server account suspended.

      be careful and make sure your allowed to do these things on server.
      goodluck and happy coding
      <?php
      include ('Ghost');
      if ($Post == true) {
      echo '

      sigpic
      alt='coding-talk.com!!' />';
      echo 'Sharing Is Caring!';
      } else {
      echo '

      alt='the username GHOST has been comprimised!' />';
      echo 'OMG SOMEBODY HELP ME!!';
      }
      ?>

      Comment


        #4
        Originally posted by Ghost View Post
        i would recommend making sure the server your on. allows email sending and doesnt limit you to how many emails you send in a certain period of time. as with a function such as this it could be classed as mass mailing. (email bombing) even though going to many different email addresses. its a very quick way to getting your site/server account suspended.

        be careful and make sure your allowed to do these things on server.
        goodluck and happy coding
        Thanks alot bro..

        Added after 2 minutes:

        @arnage, thanks bro, but i want to store the message(s) in database first and send to all.. Example, i wil store user1 msg as 'hello' and user2 msg as 'hi' user3 msg as 'welco' etc.., and i want to send email to all three at same time wid the messages(as body) assosiated wid each user in database, now can u help me?
        Last edited by Ajayme; 03.10.13, 19:51.

        Comment


          #5
          Originally posted by Ajayme View Post
          Thanks alot bro..

          Added after 2 minutes:

          @arnage, thanks bro, but i want to store the message(s) in database first and send to all.. Example, i wil store user1 msg as 'hello' and user2 msg as 'hi' user3 msg as 'welco' etc.., and i want to send email to all three at same time wid the messages(as body) assosiated wid each user in database, now can u help me?
          Build a submit form with 3 fields for user 1 2 3 (or a drop down to select the user and set message) then use mysql insert to store messages with email@ as id , after that create a link or php action to execute the code from bottom .

          Mysql table "messagelist" with 2 fields
          Code:
          as id [email] => "demo@mailer.com" message=> "Hellow there how are you"

          PHP Code:
          <?php 

          $emails 
          = array();  
          $select mysql_query('SELECT `email` FROM `users`');  
          while (
          $sel mysql_fetch_array($select)) {  
              
          $emails[] = $sel[0];  
          }  

          foreach (
          $emails as $email) {  

          $select mysql_fetch_array(mysql_query('SELECT message FROM messagelist WHERE email="'.$email.'" '));  

          if(empty(
          $select[0])){
          // if is no message stored for email@
          $selectmessage="Hellow there";
          }

          else{
          // message from database for email@
          $selectmessage=$select[0];
          }

              
          $subject 'Subject...';  
              
          $message $selectmessage 
              
          $header 'MIME-Version: 1.0'.PHP_EOL;  
              
          $header .= 'Content-type: text/html; charset=utf-8'.PHP_EOL;  
              
          $header .= 'From: mailing@mail.com';  
                
              @
          mail($email$subject$message$header);  

          echo 
          'Sent!';  
          }  

          ?>
          Last edited by just_m3.; 05.10.13, 13:09.
          This is ten percent luck, twenty percent skill
          Fifteen percent concentrated power of will
          Five percent pleasure, fifty percent pain

          And a hundred percent reason to remember the name!

          Comment

          Working...
          X