1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Phpmailer

Discussion in 'PHP' started by gasper000, Dec 29, 2008.

  1. #1
    I had some problems sending php emails using servers that require authentication like google or yahoo. I was told that PHPMAILER is the best solution to my problem. Well, I have installed it right (I think so because it I tried the installation test & there were no errors), configured the class.phpgmailer.php & tried to send an email through php codes but I always get this error "Message was not sent.Mailer error: SMTP Error: Could not connect to SMTP host."

    I tried to use smtp.gmail.com or smtp.mail.yahoo.com but it's useless..I always get the same error. I thought I should show you the class.phpgmailer.php & the php codes I use to send the email, maybe somebody can tell me how to solve such a problem. I included only the important lines in class.phpgmailer.php file.

    <?php
    class PHPMailer {
    
      /////////////////////////////////////////////////
      // PROPERTIES, PUBLIC
      /////////////////////////////////////////////////
    
      /**
       * Email priority (1 = High, 3 = Normal, 5 = low).
       * @var int
       */
      var $Priority          = 3;
    
      /**
       * Sets the CharSet of the message.
       * @var string
       */
      var $CharSet           = 'iso-8859-1';
    
      /**
       * Sets the Content-type of the message.
       * @var string
       */
      var $ContentType        = 'text/plain';
    
      /**
       * Sets the Encoding of the message. Options for this are "8bit",
       * "7bit", "binary", "base64", and "quoted-printable".
       * @var string
       */
      var $Encoding          = '8bit';
    
      /**
       * Holds the most recent mailer error message.
       * @var string
       */
      var $ErrorInfo         = '';
    
      /**
       * Sets the From email address for the message.
       * @var string
       */
      var $From              = 'my_user_name@gmail.com';
    
      /**
       * Sets the From name of the message.
       * @var string
       */
      var $FromName          = 'my_user_name@gmail.com';
    
      /**
       * Sets the Sender email (Return-Path) of the message.  If not empty,
       * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
       * @var string
       */
      var $Sender            = 'my_user_name@gmail.com';
    
      /**
       * Sets the Subject of the message.
       * @var string
       */
      var $Subject           = '';
    
      /**
       * Sets the Body of the message.  This can be either an HTML or text body.
       * If HTML then run IsHTML(true).
       * @var string
       */
      var $Body              = '';
    
      /**
       * Sets the text-only body of the message.  This automatically sets the
       * email to multipart/alternative.  This body can be read by mail
       * clients that do not have HTML email capability such as mutt. Clients
       * that can read HTML will view the normal Body.
       * @var string
       */
      var $AltBody           = '';
    
      /**
       * Sets word wrapping on the body of the message to a given number of
       * characters.
       * @var int
       */
      var $WordWrap          = 999999;
    
      /**
       * Method to send mail: ("mail", "sendmail", or "smtp").
       * @var string
       */
      var $Mailer            = 'smtp';
    
      /**
       * Sets the path of the sendmail program.****************************************************************************************************
       * @var string
       */
      var $Sendmail          = '/usr/sbin/sendmail';
    
      /**
       * Path to PHPMailer plugins.  This is now only useful if the SMTP class
       * is in a different directory than the PHP include path.
       * @var string
       */
      var $PluginDir         = '';
    
      /**
       * Holds PHPMailer version.
       * @var string
       */
      var $Version           = "2.0.3";
    
      /**
       * Sets the email address that a reading confirmation will be sent.*****
       * @var string
       */
      var $ConfirmReadingTo  = '';
    
      /**
       * Sets the hostname to use in Message-Id and Received headers
       * and as default HELO string. If empty, the value returned
       * by SERVER_NAME is used or 'localhost.localdomain'.
       * @var string
       */
      var $Hostname          = 'smtp.gmail.com';
    
      /**
       * Sets the message ID to be used in the Message-Id header.
       * If empty, a unique id will be generated.
       * @var string
       */
      var $MessageID         = '';
    
      /////////////////////////////////////////////////
      // PROPERTIES FOR SMTP
      /////////////////////////////////////////////////
    
      /**
       * Sets the SMTP hosts.  All hosts must be separated by a
       * semicolon.  You can also specify a different port
       * for each host by using this format: [hostname:port]
       * (e.g. "smtp1.example.com:25;smtp2.example.com").
       * Hosts will be tried in order.
       * @var string
       */
      var $Host        = 'smtp.gmail.com';
    
      /**
       * Sets the default SMTP server port.
       * @var int
       */
      var $Port        = 465;
    
      /**
       * Sets the SMTP HELO of the message (Default is $Hostname).
       * @var string
       */
      var $Helo        = '';
    
      /**
       * Sets connection prefix.
       * Options are "", "ssl" or "tls"
       * @var string
       */
      var $SMTPSecure = "ssl";
    
      /**
       * Sets SMTP authentication. Utilizes the Username and Password variables.
       * @var bool
       */
      var $SMTPAuth     = true;
    
      /**
       * Sets SMTP username.
       * @var string
       */
      var $Username     = 'my_user_name@gmail.com';
    
      /**
       * Sets SMTP password.
       * @var string
       */
      var $Password     = 'my_password';
    
      /**
       * Sets the SMTP server timeout in seconds. This function will not
       * work with the win32 version.
       * @var int
       */
      var $Timeout      = 10;
    
      /**
       * Sets SMTP class debugging on or off.
       * @var bool
       */
      var $SMTPDebug    = false;
    
      /**
       * Prevents the SMTP connection from being closed after each mail
       * sending.  If this is set to true then to close the connection
       * requires an explicit call to SmtpClose().
       * @var bool
       */
      var $SMTPKeepAlive = false;
    
      /**
       * Provides the ability to have the TO field process individual
       * emails, instead of sending to entire TO addresses
       * @var bool
       */
      var $SingleTo = false;
    
      /////////////////////////////////////////////////
      // PROPERTIES, PRIVATE
      /////////////////////////////////////////////////
    
      var $smtp            = NULL;
      var $to              = array();
      var $cc              = array();
      var $bcc             = array();
      var $ReplyTo         = array();
      var $attachment      = array();
      var $CustomHeader    = array();
      var $message_type    = '';
      var $boundary        = array();
      var $language        = array();
      var $error_count     = 0;
      var $LE              = "\r\n";
      var $sign_cert_file  = "";
      var $sign_key_file   = "";
      var $sign_key_pass   = "";
    Code (markup):

    The php codes I use for sending emails

     <?php  
        
      require("class.phpmailer.php");  
        
      $mail = new PHPMailer();  
        
      $mail->IsSMTP();  // telling the class to use SMTP  
      $mail->Host     = "smtp.gmail.com"; // SMTP server  
        
      $mail->From     = "my_user_name@gmail.com";  
      $mail->AddAddress("my_user_name@gmail.com");  
        
      $mail->Subject  = "First PHPMailer Message";  
      $mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";  
      $mail->WordWrap = 50;  
        
      if(!$mail->Send()) {  
        echo 'Message was not sent.';  
        echo 'Mailer error: ' . $mail->ErrorInfo;  
      } else {  
        echo 'Message has been sent.';  
      }  
      ?>  
    Code (markup):

    Any ideas ?!! Let me know if the configuration is right or not, & how may I solve this problem. Thanks.
     
    gasper000, Dec 29, 2008 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    The error is not from your code, but it's the fact that gmail and yahoo (and pretty much any server) block inbound connection to their SMTP server, which is expected.

    The good news (probably bad too) is though, to send emails from a gmail address, you don't need to use gmail's SMTP server and you don't need to authenticate yourself. Just use the default option (non-smtp) or use your own smtp server to send the emails. You can specify any 'From' email address and the email server will just trust you are who you are. Be mindful of the legal aspects of it though if you plan to do something naughty :)
     
    phper, Dec 29, 2008 IP
  3. JWRmedia

    JWRmedia Banned

    Messages:
    499
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can try making a very simple PHP mail form such as the one shown here:

    http://www.jwrmedia.com/lessons/php/mail

    And see if that works for you. If it does, you can continue to build extra features until you find the one that's not working.
     
    JWRmedia, Dec 30, 2008 IP
  4. sarkozy1

    sarkozy1 Active Member

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #4
    you can dowload and here free inbox mass mailer script phpscripts.9hz.com
     
    sarkozy1, Dec 30, 2008 IP
  5. Seraskier

    Seraskier Peon

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    php.net/function.mail

    If you are using a dedicated server with php installed, you will need to configure php.ini to work with php mail()...if this is the case, message me and ill be more than happy to help you.

    Jordan
     
    Seraskier, Dec 30, 2008 IP
  6. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    lol..nothing bad or naughty...I'm a php beginner trying to create a php form that uses the confirmation email thing to confirm registration.:)

    I don't think the google server is the problem because I can send emails using smtp.gmail.com as a server with Outlook Express & it works fine.
     
    gasper000, Jan 1, 2009 IP
  7. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7

    I tried it but it didn't work too. It says " Could not connect to SMTP host." that's why I think it's not because of the php mail. There's something wrong with configuration.Not sure but I think so.
     
    gasper000, Jan 1, 2009 IP
  8. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    lol, that script tries to make me feel good...It tells me that the email was sent so I don't get angry but when I check my email...I find nothing..!:D
     
    gasper000, Jan 1, 2009 IP
  9. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I'm developing my project on local host using wamp ...I didn't configure anything in my php.ini except

    [mail function]
    For Win32 only.
    SMTP = smtp.gmail.com
    smtp_port = 465


    For Win32 only.
    sendmail_from = my_user_name@gmail.com


    Please let me know more details because I think it's a configuration problem.
     
    gasper000, Jan 1, 2009 IP
  10. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    phper, JWRmedia, sarkozy1, & Seraskier. . .although I still can't solve this problem but I must thank you all for replying..much appreciated.
     
    gasper000, Jan 1, 2009 IP
  11. markeb

    markeb Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I noticed that you are using PHPMailer v2.0.3 (the latest version available that is PHP4-compatible).

    Try the previous PHPMailer version (v2.0.2). I was having issues connecting to SMTP servers using authentication, then I noticed that if I reverted to an older version, it worked!

    I'm not sure what the issue is, but I think this is a relatively major regression. I was testing on Windows with PHP4 and PHP5.
     
    markeb, Feb 18, 2009 IP
  12. markeb

    markeb Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Actually, I just found the bug with the PHPMailer v2.0.3 release...

    It's in the file "class.smtp.php".

    Line 1041 is:
    while($str == @fgets($this->smtp_conn,515)) {

    Line 1041 SHOULD be:
    while($str = @fgets($this->smtp_conn,515)) {
     
    markeb, Feb 18, 2009 IP
  13. scofider

    scofider Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    If you are using a dedicated server with php installed, you will need to configure php.ini to work with php mail()...if this is the case, message me and ill be more than happy to help you.
     
    scofider, Aug 13, 2009 IP