GMAIL bulk mail send

Discussion in 'PHP' started by afimafis, Jan 19, 2012.

  1. #1
    Hello PHP gurus,

    i need to have gmail bulk mail send script.i am newbie on this area.try to educate myself on php forum but it is so complex subject for me.
    i am open to any thirdparty solution or paid custom script or just fee info :)
    thanks a lot
     
    afimafis, Jan 19, 2012 IP
  2. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #2
    I use the SWIFT php mailing library for email sending. If used in a loop, you can handle mass (bulk) email sending easily. It's very simple to configure, well explained, you don't need much php knowledge to get it work. Here's my example :
    
    require_once "_swift/lib/swift_required.php"; // include the library file into your script
    $transport = Swift_SmtpTransport::newInstance('localhost', 25)
              ->setUsername('your_username_at_your_server')
              ->setPassword('your_password')
              ;
    $mailer = Swift_Mailer::newInstance($transport);
    
            while ($subscribers_row = mysql_fetch_array($result)) { // select all the recipients in this loop
    
                $sBody_newsletter = "<html>
                                        <head>
                                            <title>".$email_subject."</title>
                                            <body>
                                                <strong>Dear ".$subscribers_row['full_name']."</strong><br />
                                                ".$html_msg."
                                            <br />
                                            <hr />
                                            <center>
                                            To unsubscribe click this link :<br />
                                            <a href='unsubscribe_link_here'>Unsubscribe now!</a>
                                            </center>
                                            </body>
                                        </head>
                                    </html>";
                                    
                        //Create the message
                        $message = Swift_Message::newInstance()
                        
                          //Give the message a subject
                          ->setSubject($email_subject)
                        
                          //Set the From address with an associative array
                          ->setFrom(array('noreply@your_domain.com' => 'From NAME'))
                        
                          //Set the To addresses with an associative array
                          ->setTo(array($subscribers_row['email'] => $subscribers_row['full_name']))
                        
                          //Give it a body
                          ->setBody($sBody_newsletter, 'text/html')
                        
                          //And optionally an alternative body
                          //->addPart('<q>Here is the message itself</q>', 'text/html')
                        
                          //Optionally add any attachments
                          //->attach(Swift_Attachment::fromPath('my-document.pdf'))
                          ;
                        if ($mailer->send($message)) {
                        echo "<br />Message delivered to : <b>".$subscribers_row['email']."</b>";
                    }
                    else {
                        echo "Swift error occured...";
                    }
            }
    
    PHP:
    Depending on your hosting plan, you can send hundreds of emails easily with this library. I use it to send newsletters to all subscribed users at my site.
     
    dujmovicv, Jan 20, 2012 IP
  3. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    thanks.

    this code can be used on local host with wampserver ?
     
    afimafis, Jan 21, 2012 IP
  4. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #4
    Yes, but you'll have to configure an external mail server cause I think you can't use your local host to send emails...
     
    dujmovicv, Jan 23, 2012 IP
  5. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    thanks

    sendmail etc. php extensions can not be used as internal mail server ??
     
    afimafis, Jan 23, 2012 IP
  6. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #6
    Yes they can, but You'll have to change some things in your php.ini (you'll have to search for it, the location depends on the version of your webserver i.e c:\Xampp\apache\bin\php.ini). Open the php.ini with a text editor (notepad should be fine), locate the lines
    
    [mail function]
    ; For Win32 only.
    SMTP = localhost
    smtp_port = 25
    
    Code (markup):
    and change localhost to the SMTP server name of your ISP. Restart the Apache server and try the PHP mail() function.
     
    dujmovicv, Jan 23, 2012 IP
  7. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    thanks for advice dujmovicv :) but , i dont wanna use external smtp server.is there any internal smtp server i can use ?
     
    afimafis, Jan 23, 2012 IP
  8. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #8
    Not known to me.... I'm afraid you can't solve your issue without a working account and SMTP server of your ISP. However I think the Google mail server might work too.... I haven't tested this but would be nice to see if it's work :
    
    
    [sendmail]  
    ; you must change mail.mydomain.com to your smtp server, 
    ; or to IIS's "pickup" directory.  (generally C:\Inetpub\mailroot\Pickup) 
    ; emails delivered via IIS's pickup directory cause sendmail to 
    ; run quicker, but you won't get error messages back to the calling 
    ; application.  
    smtp_server=[COLOR=Blue][B]smtp.gmail.com[/B][/COLOR]  
    ; smtp port (normally 25)  
    smtp_port=[COLOR=Blue][B]587[/B][/COLOR]  
    ; the default domain for this server will be read from the registry 
    ; this will be appended to email addresses when one isn't provided 
    ; if you want to override the value in the registry, uncomment and modify  
    default_domain=[COLOR=Red][B]domain.com
    [/B][/COLOR]
    Code (markup):
     
    dujmovicv, Jan 24, 2012 IP
  9. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #9
    yes but gmail has restrictions to send bulk email. so need to rotate smtp server,if i need to use this kind of method.
     
    afimafis, Jan 24, 2012 IP
  10. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #10
    That's true. How many emails and how frequent do you want to send? If you have the money and don't want to use third-party services (like aweber, mailchimp, etc) you can go for a dedicated or VPS hosting plan and use your own script to send bulk email... other than that, I think I'm out of ideas... :)
     
    dujmovicv, Jan 24, 2012 IP
  11. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #11
    thanks a lot :). but i still believe that i can send email by using internal smtp server on my local host pc :)
     
    afimafis, Jan 24, 2012 IP
  12. dujmovicv

    dujmovicv Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    4
    Trophy Points:
    48
    #12
    You're welcome. I doubt that, but let us know if you manage to make this work.... :)
     
    dujmovicv, Jan 24, 2012 IP
  13. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #13
    sure man thanks
     
    afimafis, Jan 24, 2012 IP
  14. Vidzo

    Vidzo Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Your Gmail account won't last a week ;)

    Why not buy a cheap VPS, there are some cheap ones as low as $2 a month.
     
    Vidzo, Jan 25, 2012 IP
  15. afimafis

    afimafis Greenhorn

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #15
    thanks Vidzo any VPS adresses u can give me ?
     
    afimafis, Jan 25, 2012 IP
  16. Vidzo

    Vidzo Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Yes, take a look at a site lowendbox.com, I've just seen a $13/Year 128MB OpenVZ VPS.
    Chances are a lot of these providers won't exist in 24 months time offering VPS's for so little but who cares for $2/month?
     
    Vidzo, Jan 25, 2012 IP