Page 1 of 1

Swift and Free SMTP Server

Posted: Thu Aug 09, 2007 7:30 pm
by dan bloch
I have abandoned the pop3 error issue from my previous post. I can't get a straight answer from my ISP so I downloaded a product called 'Free SMTP Server'.

I have modified the code;

Code: Select all

<?php

	require_once ("SwiftMailer/lib/Swift.php")  ;
	require_once ("SwiftMailer/lib/Swift/Connection/SMTP.php");
	

	//	Start Swift	------------------------------------------------------
	//	Lang.	new Swift_Connection_SMTP(string remote_host[, int remote_port [, int encryption_level]]) 

	$smtp 	=	new Swift_Connection_SMTP( $Institution_SMTP_host_name , $Institution_SMTP_host_Port );
	
	


	//Continue like normal
	$smtp->setUsername( $Institution_SMTP_host_userName );
	$smtp->setPassword( $Institution_SMTP_host_pwd );
	
 
	$swift 	= new Swift($smtp);


	//	Create the instance and Subject	--------SUBJECT--------------
	$message 	=  new Swift_Message("Billing for ".date("F-Y" )   );

		//	Attach the message part
		$message->attach(new Swift_Message_Part( "Your Statement for ".date("F-Y" )." is attached to this email as a PDF file."    ));
 
		//	Make the attachment with the Swift_File class
		//	Swift_Message_Attachment __construct 
		//	([mixed $data = null], [string $name = null], [string $type = "application/octet-stream"], [string $encoding = "base64"], [ $disposition = "attachment"]) 

		//	By using Swift_File you save memory by not having the file contents in memory, and by not having such a large overhead 
		//	in encoding. This is the preferred method for attaching large files. 

		

		//	Additionally, using Swift_File allows you to leave out the filename parameter 
		//	in Swift_Message_Attachment since it provides the filename itself. 
		//	$message->attach(new Swift_Message_Attachment(  new Swift_File(  "INC/Statements/".$PDF_Filename   ), $PDF_Filename , "application/pdf"));
	
		//	$message->attach(new Swift_Message_Attachment(  new Swift_File(  "INC/Statements/".$PDF_Filename   ),  , "application/pdf"));
		
		$message->attach(new Swift_Message_Attachment(  new Swift_File(  "INC/Statements/".$PDF_Filename   )));


 
		//	Send it out
		//	$swift->send($message, "my-friend@host.tld", "me@my-domain.tld");
		//	$sent	returns the number of records sent
		//	recipients-----> email and Name-----along with----->  Senders email and Name   
		$From     		=	$InstitutionDepartmentEmail    ;
		$FromName 		=	$InstitutionName."  ".$InstitutionDepartmentName ;
		
		
	$sent = $swift->send( $message  , new Swift_Address(  $Department_email ), new Swift_Address( $From  ,  $FromName  ));

		
?>

and now I get the following error.


Fatal error: Uncaught exception 'Swift_Connection_Exception' with message 'The SMTP connection did not allow the command 'EHLO [127.0.0.1]' to be sent. (fsockopen: #0) ' in C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift\Connection\SMTP.php:265 Stack trace: #0 C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift.php(306): Swift_Connection_SMTP->write('EHLO [127.0.0.1...', '??') #1 C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift.php(269): Swift->command('EHLO [127.0.0.1...', 250) #2 C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift.php(229): Swift->handshake(Object(Swift_Events_ResponseEvent)) #3 C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift.php(102): Swift->connect() #4 C:\Apache\Apache2\WEB_Pages\INC\ar_DeptStatements_SwiftMailer.php(20): Swift->__construct(Object(Swift_Connection_SMTP)) #5 C:\Apache\Apache2\WEB_Pages\ar_DeptStatements_pdfAtch.php(144): include('C:\Apache\Apach...') #6 {main} thrown in C:\Apache\Apache2\WEB_Pages\INC\SwiftMailer\lib\Swift\Connection\SMTP.php on line 265



when I do a ping localhost it passes.
when I do a telnet localhost 25 the screen header says "Telnet localhost and the drive (c:>) disappears leaving only a blinking cursor.


Thank You for sharing your time with me.

dan bloch

Posted: Fri Aug 10, 2007 1:38 am
by Chris Corbyn
Sound like your smtp server is not working. Telnet should not just give a blinking cursor (it does that while it *tries* to connect). When you use telnet to connect to smtp you should see a a greeting message from the server. Try connecting to smtp.swiftmailer.org for example (although my server won't let you send mail through it).