Php mail() code in this situation

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

  • just_m3.
    replied
    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.

    Leave a comment:


  • Ajayme
    replied
    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.

    Leave a comment:


  • Ghost
    replied
    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

    Leave a comment:


  • arnage
    replied
    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!'

    Leave a comment:


  • Ajayme
    started a topic Php mail() code in this situation

    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..
Working...
X