FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Cannot send emails
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Cannot send emails [message #173149] Thu, 24 March 2011 17:39 Go to next message
Marco is currently offline  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 Go to previous messageGo to next message
Marco is currently offline  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 Go to previous message
Marco is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: php includes and ajax
Next Topic: Why would chmod( ... ) fail with "No such file or directory"
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 22:19:25 GMT 2024

Total time taken to generate the page: 0.04297 seconds