External SMTP server, PHP

Install PEAR::Mail

Install pear mail

$ pear -a Mail

also check installed ‘pear’

$ pear list

Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.4.0 stable
Auth_SASL 1.1.0 stable
Console_Getopt 1.4.1 stable
Mail 1.4.1 stable
Net_SMTP 1.8.0 stable
Net_Socket 1.2.2 stable
PEAR 1.10.1 stable
PEAR_Manpages 1.10.0 stable
Structures_Graph 1.1.1 stable
XML_Util 1.3.0 stable

Smtp Client sample

function smtp_client($to, $sub, $body, $nam, $from) {
	require_once "Mail.php";

	define( "MAIL_CHARSET", "ISO-2022-JP" );

	$param = array(
		'host'=>'leo.ntools.net',
		'port'=> 25 , // if using provider smtp, 587
		'auth' => true,
		'username' => 'user',
		'password' => 'xxxxxxxx',
		'timeout' => 10
	);

	$sub = mb_encode_mimeheader( $sub, MAIL_CHARSET );
	$body = mb_convert_encoding( $body, MAIL_CHARSET, "UTF-8" );

	$header = array(
		'From' => $from,
		'To' => $to,
		'Subject' => $sub,
		'Content-Type' => "text/plain; charset=" . MAIL_CHARSET
	);

	$obj = Mail::factory( "smtp", $param );
	$recipients = array_merge( $to, $cc, $bcc );
	$ret = $obj->send( $recipients, $header, $body );
	if ( PEAR::isError( $ret ) ) {
		echo "Code[" . $ret->getCode() . "], Msg[" . $ret->getMessage() . "]\n";
                return FALSE;
	}
        return TRUE;
}