Cannot send emails

  • Follow


Hi,

I have problems sending mails. The messages are as follows:

PHP Warning:  Connection refused in /usr/share/php/PEAR.php on line 873
PHP Warning:  Failed to connect socket: Connection refused in /usr/share/php/PEAR.php on line 873

I used the following code:

<?php
  require_once 'Mail.php';
  require_once 'PEAR.php';

  define('MYCLASS_ERROR_CODE', 1);
  PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);

  $from_name = 'Marco';
  $to_name   = 'Recipient';
  $subject   = 'Testmail';
  $mailmsg   = 'dummy content';

  $From = "From: ".$from_name." <myaddress@domain.net>";
  $To   = "To: ".$to_name." <recipientaddress@domain.net>";

  $recipients              = "recipientaddress@domain.net";
  $headers["From"]         = $From;
  $headers["To"]           = $To;
  $headers["Subject"]      = $subject;
  $headers["Reply-To"]     = "myaddress@domain.net";
  $headers["Content-Type"] = "text/plain; charset=UTF-8";
  $headers["Return-path"]  = "myaddress@domain.net";
  
  $smtpinfo["host"]     = "server.com";
  $smtpinfo["port"]     = "25";
  $smtpinfo["auth"]     = true;
  $smtpinfo["username"] = "myusername";
  $smtpinfo["password"] = "verysecret";

  $mail_object =& Mail::factory("smtp", $smtpinfo);

  $mail_object->send($recipients, $headers, $mailmsg);
?> 

When I use the same host, port, username and password in my mail program I can
send mails. What is wrong with this setup?


Marco

0
Reply Marco 3/24/2011 5:39:46 PM

I tried
  telnet server.com 25
and I got:
  telnet: Unable to connect to remote host: Connection refused

This should work, if I'm not mistaken, right? I have no clue, where the
problem could be. Why is the connection refused?


Marco

0
Reply Marco 3/24/2011 5:53:28 PM


Sorry for talking to myself. Here's the solution:

1) Try the correct port: 465
2) Use SSL: $smtpinfo["host"]     = "ssl://server.com";
3) Happy Mailing :)

Thanks for listening.

Marco

0
Reply Marco 3/24/2011 6:06:20 PM

2 Replies
192 Views

(page loaded in 0.182 seconds)

Similiar Articles:













7/11/2012 1:59:47 PM


Reply: