tags:

views:

136

answers:

4

i am using mail() function to send email from PHP without any authentication.

This function only work on my web server, but does not work on a local machine.

I am looking for best PHP function to send a email with authentication which would work on any machine without modifying the php.ini

i am using PHP with IIS and windows

thanks

+1  A: 

You should run a local smtp server. This will let mail() just work as long as that program is running. There are other similar servers that will write mail to a file so no mail actually goes out on the dev enviroment.

Mail() is the way to go for sending mail. you just have a config issue locally :D

Byron Whitlock
I've found it works even without an smtp server... which does seem slightly odd now I think about it!
Rich Bradshaw
Maybe OSX comes with one...
Rich Bradshaw
+2  A: 

Another possibility is to install mail and net_smtp through pear.

pear install Mail
pear install Net_Smtp

then you have the possibility to send mail with SMTP authentication to another server:

require_once "Mail.php";

$body = "Mein Mail Body\n";
$subject = "Mail mit SMTP Authentifizierung";
$mail_to = "[email protected]";
$mail_from = "[email protected]";

//SMTP Verbindungsdaten
$host = "smtp.meinemailserver.de";
$username = "phpmailer";
$password = "SuperGeheim";

$smtp = Mail::factory('smtp',
 array (
 'host' => $host,
 'auth' => true,
 'username' => $username,
 'password' => $password
));

$headers = array (
 'From' => $mail_from,
 'To' => $mail_to,
 'Subject' => $subject
);
$mail = $smtp->send($mail_to, $headers, $body);

if (PEAR::isError($mail)) {
 echo "Fehler beim Versender der E-Mail : ". $mail->getMessage();
}

(taken from http://www.jgeppert.com/2009/06/php-e-mail-mit-smtp-authentifizierung-versenden/)

Aurril
i am using PHP with IIS and windows.....
air
Another way is to configure the php.ini
Aurril
You can install PEAR on Windows aswell:In your PHP Installation folder should be a batch file named "go-pear.bat"Use this file to install pear.
Aurril
sorry i dont know how to install pear, i have following text in go-pear.bat@ECHO OFFset PHP_BIN=php.exe%PHP_BIN% -d output_buffering=0 PEAR\go-pear.pharpausecan you tell me how to install it?
air
Start cmd.exe and change into your php directory, where go-pear.bat resides.Then just type "go-pear" and follow the instructions on the screen.
Aurril
air
A: 

If all you need is a working SMTP server to test in your own box, run this little guy on your box so you can test mail stuff without changing your mail-handling code.

http://www.softstack.com/freesmtp.html (free standalone simple stmp server)

Infinity
A: 

I had this problem earlier this week, and found SwiftMailer. I've only heard good things about it. Worked fine for me.

It can send by SMTP, sendmail, or mail(). For local development, you would have to connect to a SMTP server, either one you run locally, or an external.

Austin Hyde