Cannot send emails [message #173149] |
Thu, 24 March 2011 17:39 |
Marco
Messages: 11 Registered: March 2011
Karma: 0
|
Junior Member |
|
|
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(at)domain(dot)net>";
$To = "To: ".$to_name." <recipientaddress(at)domain(dot)net>";
$recipients = "recipientaddress(at)domain(dot)net";
$headers["From"] = $From;
$headers["To"] = $To;
$headers["Subject"] = $subject;
$headers["Reply-To"] = "myaddress(at)domain(dot)net";
$headers["Content-Type"] = "text/plain; charset=UTF-8";
$headers["Return-path"] = "myaddress(at)domain(dot)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
|
|
|
Re: Cannot send emails [message #173150 is a reply to message #173149] |
Thu, 24 March 2011 17:53 |
Marco
Messages: 11 Registered: March 2011
Karma: 0
|
Junior Member |
|
|
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
|
|
|
Re: Cannot send emails [message #173152 is a reply to message #173150] |
Thu, 24 March 2011 18:06 |
Marco
Messages: 11 Registered: March 2011
Karma: 0
|
Junior Member |
|
|
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
|
|
|