Page 1 of 1

unknown badresponseexception error?

Posted: Wed Jun 20, 2007 5:19 pm
by geodeath
Hello all,

I tried using swiftmailer on my server.
I created an email account ("mailer@mydomain.com") and the smtp address is mail.mydomain.com.
I created the following php file which grabs the variables from a flash site and (supposedly) sents them through email
to the email address i coded.

However when i try to run it, it gives me the following error :

Code: Select all

Fatal error:
Uncaught Error of type [swift_badresponseexception] with message [Expected response code(s) [250] but got response []]
@0 swift::send() in /home/user/public_html/mydomain/scripts/mail.php on line 37
@1 swift::reset() in /home/user/public_html/mydomain/swift/Swift.php on line 465
@2 swift::command() in /home/user/public_html/mydomain/swift/Swift.php on line 361

in /home/user/public_html/mydomain/swift/Swift/Errors.php on line 99
The php file is the following :

Code: Select all

<?php

$Name = $_POST["Name"];
$Email = $_POST["Email"];
$Subject = $_POST["Subject"];
$Message = $_POST["Message"];


$ToEmail = "mymail@gmail.com";

$EmailBody = "&#908;&#957;&#959;&#956;&#945;/name: ".$Name."\nE-mail: ".$Email."\n&#920;&#941;&#956;&#945;/Subject: ".$Subject."\n&#924;&#973;&#957;&#951;&#956;&#945;/Message: ".$Message;

$EmailFooter="\n\n\nThis message was sent through the website contact form";

$Message = $EmailBody.$EmailFooter;

//Load in the files we'll need
require_once "../swift/Swift.php";
require_once "../swift/Swift/Connection/SMTP.php";
 
//Start Swift
$conn =& new Swift_Connection_SMTP("mail.mydomain.com");
$conn->setUsername("user@mydomain.com");
$conn->setPassword("password");

$swift =& new Swift($conn);

 
//Create the message
$message =& new Swift_Message($ToSubject, $Message);
 
//Now check if Swift actually sends it
if ($swift->send($message, "mymail@gmail.com", "mymail@gmail.com")) $something="0";
else $something="1";



?>
What am i doing wrong? I cant really tell the error. It might be that its clost to 1:30 am here and i am almost asleep but who knows? :P
thanks in advance for any help.

George

Posted: Wed Jun 20, 2007 5:23 pm
by Weirdan
I cant really tell the error.
From what I see Swift hasn't got any response from your mail server.

Posted: Wed Jun 20, 2007 5:29 pm
by Chris Corbyn
Yeah it appears that the mail server is not responding correctly. This could be for any number of reasons... the most obvious one I should ask is: Have you tried wihout the username and password? If you're connecting from within the network it's probably not needed and may simply cause problems.

Posted: Wed Jun 20, 2007 11:55 pm
by geodeath
well, of course i tried not using username & password before i used them to no avail.

What i did just now was to see if this smtp really works by trying it in thunderbird in a new account.
It works! Which brings me to believe that the host might be blocking php access to the smtp or something like that.
I cant think of something else. I should at least get a connection. I can always use the gmail smtp but there is no reason
to not talk to the hosting co to take care of it.

Will get in touch will them and when i have an answer i ll post it here.

EDIT: What i forgot to say is that when i execute the script without the username & password at all, the script executes without
returning an error. However, is that ok? What does a username & password have to do with connecting at all? I should have got
an error at the very least, right?

Posted: Thu Jun 21, 2007 12:43 am
by Chris Corbyn
Sounds like a relaying denied problem then. Without the username and password do:

Code: Select all

$swift =& new Swift(new Swift_Connection_SMTP($hostname));
$swift->log->enable();

// .. snip ..
// send your message
// .. snip ..

echo "<pre>";
$swift->log->dump();
This shoud hopefully clarify what's going on. It's quite probable that the SMTP server is for incoming mail for the domain it runs on only.

Posted: Thu Jun 21, 2007 1:06 am
by geodeath
from the error log, it seems i have to login to pop first or use 550 smtp authentication

Code: Select all

++ Enabling logging
>> MAIL FROM: 
<< 250 OK
>> RCPT TO: 
<< 550-ns2.host.com (http://www.mydomain.gr) [64.247.42.70]:52243 is
550-currently not permitted to relay through this server. Perhaps you have not
550-logged into the pop/imap server in the last 30 minutes or do not have SMTP
550 Authentication turned on in your email client.
!! Expected response code(s) [250] but got response [550-ns2.host.com (http://www.mydomain.gr) [64.247.42.70]:52243 is
550-currently not permitted to relay through this server. Perhaps you have not
550-logged into the pop/imap server in the last 30 minutes or do not have SMTP
550 Authentication turned on in your email client.]
>> RSET
<< 250 Reset OK
So what would be wiser? Choosing to specify a username & password will not connect at all as seen in my first post.
Should pop access first be the way?

Posted: Thu Jun 21, 2007 6:16 am
by Chris Corbyn
OK, this server does not use authentication in the normal sense... it uses Pop Before SMTP authentication.

Read the Pop Before SMTP section on this page to see how you use that ;)

http://www.swiftmailer.org/wikidocs/v3/smtpauth (Bottom section on the page)

Posted: Wed Jun 27, 2007 12:56 am
by geodeath
thanks for the info.
I managed to make it work. :)

Its magical how much time work can take away.
I didnt post for quite some days :)