#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    129
    Rep Power
    9

    php PEAR Email not working


    I have successfully written code to send emails from my web site (using the PEAR system). I then migrated the site to SSL for security reasons and the code still worked. The code essentially is as follows:

    Code:
    include "Mail.php"; 
    include "Mail/mime.php"; 
    
    $sender = "myname@gmail.com";
    $subject = "test";
    $body = "TEST EMAIL";
    $html = "<html><body>".$body."</body></html>";
    $text = $body;
    $username = "webmaster@somename.com";
    $password = 'xxxxxx'; 
    $crlf = "\n";
    $hdrs = array(
                   'From'    => 'webmaster@somename.com',             
                  'Subject' => $subject
                  );
    $mime = new Mail_mime(array('eol' => $crlf));
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);
    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    $to = "me@gmail.com";
    $mail =& Mail::factory('smtp', array('host' => $host,  'auth' => true, 'username' => $username, 'password' => $password)    );
    $mail->send($to, $hdrs, $body);
    Because I am now trying to send emails to more than 300 people, I have had to purchase a VPS package. As a result the above code no longer works.

    So, I have rewritten it as follows:

    Code:
    include "Mail.php"; 
    include "Mail/mime.php"; 
    
    $sender = "webmaster@somename.com";
    $subject = "test";
    $body = "TEST EMAIL";
    
    $from = "webmaster <webmaster@somename.com>"; 
    $host = "ssl://mail.somename.com"; 
    $username = "webmaster@somename.com"; 
    $password = 'xxxxxx'; 
    $body = "TEST EMAIL";
    $html = "<html><body>".$body."</body></html>";
    $text = $body;
    $port = 465;
    $crlf = "\n";
    $hdrs = array(
                  'From'    => 'webmaster@somename.com',
                  'Subject' => $subject
                  );
    $mime = new Mail_mime(array('eol' => $crlf));
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);
    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    $to = "me@gmail.com";
    $params['host'] = 'ssl://mail.somename.com';
    $params['port'] = '465';
    $params['auth'] = 'true';
    $params['SMTPAuth'] = 'true';
    $params['SMTPSecure'] = 'ssl';
    $params['username'] = 'webmaster@somename.com'; 
    $params['password'] = 'xxxxxx'; 
    
    //$mail->IsSMTP();
    
    $mail =& Mail::factory('smtp', $params );
    $mail->send($to, $hdrs, $body);
    The code executes but no email is sent.

    If I remove the nulls on the line $mail->IsSMTP(); then the code does not execute.

    So, if someone can help I would be very grateful.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,395
    Rep Power
    9645
    Change the two includes to be require_onces instead, uncomment the IsSMTP line and realize that you can't call a method on a variable if the variable has not been defined yet.

    Then look in your server error logs for any messages from PHP.
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Caro, Michigan
    Posts
    14,810
    Rep Power
    4536
    wow, PEAR is still a thing? Impressive...
    -- Cigars, whiskey and wild, wild women. --
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    129
    Rep Power
    9
    Thank you requinix. For simple people like me can you tell me what you mean by "can't call a method on a variable if the variable has not been defined yet.". Which variable am I calling before defining it please?
  8. #5
  9. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,395
    Rep Power
    9645
    PHP Code:
    //$mail->IsSMTP();

    $mail =& Mail::factory('smtp'$params ); 
    How do you expect to call IsSMTP() on $mail before you even define what $mail is?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    129
    Rep Power
    9
    Thank you. I'll rectify. However, the problem appears to be resolved.

    My password was 14 alphanumeric characters.

    It appears that under VPS this is not strong enough and has been increased to 16 characters including such characters as %$&_ etc.!!!!!!!!

IMN logo majestic logo threadwatch logo seochat tools logo