www.webdeveloper.com
Results 1 to 5 of 5

Thread: using database and Mail()

  1. #1
    Join Date
    Dec 2007
    Posts
    30

    using database and Mail()

    I am pretty green when it comes to PHP and mySQL but am trying to make a conscious effort to self teach. I have started what I hope is on the right path to creating function in php that uses email address in a array from a database to send emails. If anybody could point me in the correct direction of what I am doing wrong that would be great.

    Code:
    <?
    //connect to database
    // query database for column 'emails'
    
    
    //creat an array from email address in database... not sure how to do this.......
    
    $subject = 'mail';
    $message = 'this is a test eamil';
    
    //add headers
    
    count = email_array.length;
    
    for (i = 0; i < count; i++){
    		$email_adress = email_array[i];
    		mail($email_address,$subject,$message);
    		}
    		
    		?>
    I am sure there has got to be a tutorial out there just not having much luck in finding one so thanks ahead of time for any help.

    denoteone.

  2. #2
    Join Date
    May 2007
    Posts
    184
    PHP Code:
    //use mysql_connect() function
    //use mysql_query() function for getting 'emails'

    $subject 'mail';
    $message 'this is a test email';

    while(
    $result mysql_fetch_array($query_result))
    {
        
    $email_adress $result["emails"];
        
    mail($email_address,$subject,$message);
    }
            
    ?> 
    $query_result is what mysql_query() returns.
    mysql_fetch_array() returns an associative array of the tables columns

  3. #3
    Join Date
    Dec 2007
    Posts
    30
    Running a while loop until the array does not contain an email address makes sense but is it the most efficient way to send out newsletters? I know there is software out there but is seems like it should be pretty straight forward to develop yourself......

  4. #4
    Join Date
    May 2007
    Posts
    184
    Quote Originally Posted by Denoteone
    Running a while loop until the array does not contain an email address makes sense but is it the most efficient way to send out newsletters? I know there is software out there but is seems like it should be pretty straight forward to develop yourself......
    No it's not really efficient at all if you sending out huge bulks of emails. Have you looked at the phpMailer class.

    This will probably help you.
    http://www.schogini.com/articles/Sen...-with-PHP.html
    Check out the send() function and the end of this article.

  5. #5
    Join Date
    Dec 2007
    Posts
    30

    thanks ss1289

    Thank you SS1289.
    I think I will take a look at the source for the free bulk mailers.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles