Welcome Guest, Not a member yet? Register   Sign In
Sending emails to multiple users with google mail...
#1

[eluser]Twisted1919[/eluser]
My hosting server has a limit of 500 emails per day . When i reach that limit , i can't send any mails anymore.
So i tought , using google mail account would do the trick .
One of my domains has mail server hosted by google at google apps so i went this way .
As you know , google apps mail also has a limit of 500 emails per day on single account ,
so i created 3 accounts (testing for now ) so i can send 1500 mails [if i got it right] .
Bellow is my code for sending mails from those accounts :
Code:
function index()
    {
    
        $message = 'Some HTML content';
    
        $this->db->select('profile_id_mess');
        $this->db->from('sgc_profiles');
        $this->db->where('profile_active' , 1);
        $this->db->order_by('profile_id','DESC');
        $this->db->limit(1300);
        $query = $this->db->get();
        $i = 0 ;
        foreach($query->result_array() AS $row )
        {
        $pos1 = strpos($row['profile_id_mess'] , '*' );
        $pos2 = strpos($row['profile_id_mess'] , 'yahoo');
        $pos3 = strpos($row['profile_id_mess'] , 'gmail');
        $pos4 = strpos($row['profile_id_mess'] , '@');
        
            if($pos1 === FALSE AND $pos2 === FALSE AND $pos3 === FALSE AND $pos4 === FALSE)
            {
            ++$i ;
            if( $i > 0 AND $i < 450 )
                {
                $smtp_user = '[email protected]';
                $smtp_pass = 'first password';        
                 }        
            elseif($i > 450 AND $i < 900 )
                {
                $smtp_user = '[email protected]';
                $smtp_pass = 'second password ';
                }
            elseif( $i > 900 AND $i < 1300 )
                {
                $smtp_user = '[email protected]';
                $smtp_pass = 'third password';
                }    
            $config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => $smtp_user ,
                'smtp_pass' => $smtp_pass ,
                'useragent' => 'My Site Agent ',
                'priority'  => 3 , //1-high,3-medium,5-normal
                'mailtype'  => 'html'
                );            
            $this->load->library('email', $config);
            
            $this->email->set_newline("\r\n");
            $this->email->from($config['smtp_user'], 'Info MySite');
            $this->email->reply_to('one_of_my_address', 'MySite Administrator');
            $this->email->to($row['profile_id_mess'].'@yahoo.com');
            
            $this->email->subject('HB ');
            $this->email->message($message);

            if (!$this->email->send())
            {
            show_error($this->email->print_debugger());
            }
            else
            {
            echo $i. ' Your e-mail has been sent!<br />';
            }
            
            }
        }
        
    }

Now , when i try to send the mails , sometimes it sends 200 or 300 once , but sometimes just 10 , then i get an error with debugger , or i get an internal server error .

What can cause the problem ?
Should i use sleep() for some seconds after x mails are sent ?
How should i do to send all the emails through google mail ?
Thanks!
#2

[eluser]Dam1an[/eluser]
How many do you plan on sending a day? Or to give a more accurate idea, how many do you expect to send over the course of a month, cause if its not in the region of tens of thousands each day, you could probably just ask your provider to raise the limit... you'd be suprised how much a polite email/call can get you

They are even more likely to agree if you send several times your daily limit, but only once a week
#3

[eluser]Twisted1919[/eluser]
I only send emails to the new registered users and sometimes to all users sending some important news or updates .
That is the problem , now i have 9829 registered users and i try to send an mass email to notify them of some changes on the site .
This situation may appear few times in a mounth so the number of send mails will differ ...
#4

[eluser]Dam1an[/eluser]
Well, with most types of mailing lists, there's no need to send them all simultaneously, but stagger it over a few days...
Or, you could use some 3rd party service for mailing lists, and then just do the registration emails yourself
#5

[eluser]Twisted1919[/eluser]
mailing lists ? i don't know to well this subject ...
Can you point me to some site or give me an clean example ?
Thx.
#6

[eluser]Daniel Moore[/eluser]
If I recall correctly, the limit the hosting provider places on your email account is an SMTP relay limit. If you use a method other than SMTP, like PHP's built-in mail() function, wouldn't this bypass that restriction?

I have a limit of 250 per day, but have successfully sent out 1500 in one day using mail().
#7

[eluser]Dam1an[/eluser]
PHP List is the most used mailing list manager in PHP, but its a self hosted solution.

Basically a mailing list system lets you store a list of email address to send your newsletters/notices/whatever to, and takes care of sending them (they also have a lot of extra functionality, but thats it at the most basic level)

If you can find a web host which doesn't limit the number of emails/day you can send, or has a high enough cap, you could just run PHP List from there (I'm sure you could then hook into it remotely from CI if need be) or use it stand alone
#8

[eluser]Twisted1919[/eluser]
[quote author="Daniel Moore" date="1240515843"]If I recall correctly, the limit the hosting provider places on your email account is an SMTP relay limit. If you use a method other than SMTP, like PHP's built-in mail() function, wouldn't this bypass that restriction?

I have a limit of 250 per day, but have successfully sent out 1500 in one day using mail().[/quote]

I can use just smtp auth , and that's all i get ...
I can't move my site from there because the hosting is very very good and fast .


Quote:PHP List is the most used mailing list manager in PHP, but its a self hosted solution.

Basically a mailing list system lets you store a list of email address to send your newsletters/notices/whatever to, and takes care of sending them (they also have a lot of extra functionality, but thats it at the most basic level)

If you can find a web host which doesn’t limit the number of emails/day you can send, or has a high enough cap, you could just run PHP List from there (I’m sure you could then hook into it remotely from CI if need be) or use it stand alone

Hmm ... i doubt that this can help me .
The last solution is renting a dedicated mail server but it doesn't worth ...
I'm out of ideas over here Smile
#9

[eluser]Twisted1919[/eluser]
Even if i didn't find an valid solution for my problem ,
i noticed a thing regarding the email class and public smtp servers
When trying to send HTML mail like this :
Code:
$message = 'HTML CONTENT ';
$config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'mail.myserver.info',
                'smtp_port' => 25,
                'smtp_user' => '[email protected]' ,
                'smtp_pass' => 'mypassword' ,
                'useragent' => 'My Site Agent ',
                'validate'  => TRUE ,
                'priority'  => 3 , //1-high,3-medium,5-normal
                'mailtype'  => 'html'
                );
                $this->load->library('email', $config);
            
            $this->email->set_newline("\r\n");
            $this->email->from($config['smtp_user'], 'Info MySite');
            $this->email->reply_to('[email protected]', 'Site  Administrator');
            $this->email->to('[email protected]');
            
            $this->email->subject('HB ');
            $this->email->message($message);

            if (!$this->email->send())
            {
            show_error($this->email->print_debugger());
            }
            else
            {
            echo $i. ' Your e-mail has been sent!<br />';
            }

I got the following error :
Code:
220 mail.server.info ESMTP

hello: 250-mail.server.info
250-AUTH LOGIN CRAM-MD5 PLAIN
250-AUTH=LOGIN CRAM-MD5 PLAIN
250-STARTTLS
250-PIPELINING
250 8BITMIME

from: 250 ok

to: 250 ok

data: 354 go ahead

451 See http://pobox.com/~djb/docs/smtplf.html.
Urmatoarea eroare SMTP a avut loc: 451 See http://pobox.com/~djb/docs/smtplf.html.
Nu s-a putut trimite email folosind SMTP. Serverul dumneavoastra s-ar putea sa nu fie configurat pentru a trimite mail-uri prin aceasta metoda.

User-Agent: CodeIgniter
Date: Thu, 23 Apr 2009 19:42:28 +0300
From: "Info MySite"
Return-Path:
Reply-To: "Site Administrator"
To: [email protected]
Subject: HB
X-Sender: [email protected]
X-Mailer: My Site Agent
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_49f09a746924c"
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_49f09a746924c
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

So the quick fix is to add to config array following values :

Code:
$config = Array(
                'protocol' => 'smtp',
                'smtp_host' => 'mail.server.info',
                'smtp_port' => 25,
                'smtp_user' => '[email protected]' ,
                'smtp_pass' => 'smtp password' ,
                'useragent' => 'My Site Agent ',
                'validate'  => TRUE ,
                'priority'  => 3 , //1-high,3-medium,5-normal
                'mailtype'  => 'html' ,
                'crlf'        => "\r\n" ,
                'newline'   => "\r\n"
                );

This way , the html mail is sent .
Hope it helps Smile




Theme © iAndrew 2016 - Forum software by © MyBB