Page 1 of 1

php mailer and free smtp

Posted: Thu Aug 09, 2007 6:41 pm
by dan bloch
I am a wamp developer and I have installed php mailer and free smtp.

When I send the following test to the free server;

Code: Select all

<?php
	$to = "XXXXXX@msn.com"; $subject = "test this"; $message = "sent";
	if (mail($to, $subject, $message)) echo "success!";
?>

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache\Apache2\WEB_Pages\mail_test.php on line 3

The php.ini is set to localhost and port 25.

ping localhost works OK.


the php code looks like this:

Code: Select all

//	phpMailer---------------------------------
		require_once ("phpmailer/phpmailer.lang-en.php");
		require_once ("phpmailer/class.phpmailer.php");
		require_once ("phpmailer/class.smtp.php");
	//	phpMailer---------------------------------
	
	
	
	// Instantiate your new class
	$mail = new phpMailer;
	
	
	$mail->IsSMTP(); // send via SMTP
	$mail->SMTPAuth = true;
	
                $mail->From     		=	$InstitutionDepartmentEmail    ;
                $mail->FromName 		=	$InstitutionName."  ".$InstitutionDepartmentName ;
                $mail->Host     		=	$Institution_SMTP_host_name ;
    
	$mail->Username   		=	$Institution_SMTP_host_userName ;
	$mail->Password			=	$Institution_SMTP_host_pwd ;
	//	$mail->HostTLS			=	$Institution_SMTP_host_TLS	;
               $mail->Mailer   		= "smtp";                         // Alternative to IsSMTP()
               $mail->WordWrap 		= 75;
	//-----------------------------------------------------
	
	$Subject 	= "Billing for ".date("F-Y" );
	$Body 	= "Your Statement for ".date("F-Y" )." is attached to this email as a PDF file."  ;
	
	//-----------------------------------------------------
	// Now you only need to add the necessary stuff
	$mail->AddAddress(  $Department_email  );
	$mail->Subject = $Subject  ;
	$mail->Body    = $Body  ;
	
	
	$mail->AddAttachment("INC/Statements/".$PDF_Filename );  // optional name

	if(!$mail->Send())
	{
	   echo 'Message was not sent.';
	   echo 'Mailer error: ' . $mail->ErrorInfo;
	}

	else
	{
	   echo 'Message has been sent.';
	}

		
	$mail->ClearAddresses();
	$mail->ClearAttachments();
and gives this answer

Warning: fputs(): supplied argument is not a valid stream resource in C:\Apache\Apache2\WEB_Pages\INC\phpmailer\class.smtp.php on line 146

Warning: fgets(): supplied argument is not a valid stream resource in C:\Apache\Apache2\WEB_Pages\INC\phpmailer\class.smtp.php on line 1024
Message was not sent.Mailer error: Language string failed to load: from_faileddanbloch1@msn.com
Warning: fputs(): supplied argument is not a valid stream resource in C:\Apache\Apache2\WEB_Pages\INC\phpmailer\class.smtp.php on line 146

Warning: fgets(): supplied argument is not a valid stream resource in C:\Apache\Apache2\WEB_Pages\INC\phpmailer\class.smtp.php on line 1024
Message was not sent.Mailer error: Language string failed to load: from_failed and xxxx@msn.com (my email address).



thank you for sharing your time with me.


dan bloch

Posted: Thu Aug 09, 2007 7:12 pm
by Christopher
Not an answer to your question, but you may want to try SwiftMailer as there is a support form here for that package.

Posted: Thu Aug 09, 2007 7:29 pm
by nickvd
I'll bet your smtp server isnt running, or is blocking connections, or is not listening on the right ip/port...

Try to connect to your smtp server via telnet...

start->run->telnet localhost 25

if that hangs, then the problem is not php/phpmailer, but with the smtp server you've installed.

I TOO can't recommend swiftmailer enough, it is much better than any other php based solution you will find.

Posted: Fri Aug 10, 2007 4:40 am
by dancaragea
Swiftmailer is great, indeed, and you should use it if you can but you will face the same problem: the smtp server (the part of the mail server that sends emails). Obviously, you don't have a mail server on your computer so you will have to use another one. To use the built in function mail() on windows you just have to change in php.ini this part:
[mail function]
; For Win32 only.
SMTP = mail.someserver.com

; For Win32 only.
sendmail_from = user@someserver.com

Then restart apache.

The mail server can be the mail server you use in your mail application (outlook, thunderbird, etc).

The same smtp server can be used for swiftmailer.
Your php.ini should be in your windows folder I think...