1 Replies - 727 Views - Last Post: 06 February 2013 - 01:23 PM Rate Topic: -----

#1 codine24/7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 12-February 12

php pear mail

Posted 06 February 2013 - 03:07 AM

i am using the pear mail package to send an email.

it is for a new client of mine so any help is greatly appreciated [=

this is the error i get

Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Permission denied (code: -1, response: )]

require_once "Mail.php";

        $from = "<from.gmail.com>";
        $to = "<to.gmail.com>";
        $subject = "Hi!";
        $body = "Hi,\n\nHow are you?";

        $host = "ssl://smtp.gmail.com";
        $port = "465";
        $username = "username@gmail.com";  
        $password = "password";

        /**/
        $headers = array ('From' => $from,
          'To' => $to,
          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
          array ('host' => $host,
            'port' => $port,
            'auth' => true,
            'username' => $username,
            'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
          echo("<p>" . $mail->getMessage() . "</p>");
         } else {
          echo("<p>Message successfully sent!</p>");
         }



i have installed pear mail and NET_SMTP and am using a new version of php.

i recently used the class.phpmailer.php on windows and it worked fine. But on my vps it is giving me the same error.

the code i am trying to use for this class is as follows

require_once('../sitelib/mail/class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

$mail->IsSMTP(); // telling the class to use SMTP

try {
  $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
  $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
  $mail->Username   = "user@gmail.com";  // GMAIL username
  $mail->Password   = "password";            // GMAIL password
  $mail->AddAddress('address@gmail.com', 'John Doe');
  $mail->SetFrom('me@gmail.com', 'First Last');
  $mail->AddReplyTo('me@gmail.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML('<b>hello world</b>');
  $mail->Send();
  echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}



This code above produces this error message

SMTP -> ERROR: Failed to connect to server: Permission denied (13)
SMTP Error: Could not connect to SMTP host.


I know the code works because i ran it off of XAMP on windows.


I am no longer testing code on my windows os. Right now i am testing my code on centos 6 32 bit.

my vps is centos 5 32 bit.

i am using apache. I think the problem may be because of the config file.

Is This A Good Question/Topic? 0
  • +

Replies To: php pear mail

#2 codine24/7  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 12-February 12

Re: php pear mail

Posted 06 February 2013 - 01:23 PM

setsebool -P httpd_can_network_connect 1

i ran this under roor in the terminal and it all worked!

im not sure exactly what it did, i think it just allowed my sockets to connect to a different network.

Would anyone recoment phpMailer over pear mail? or even vise versa?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1