tags:

views:

88

answers:

7

I'm would like to use PHP to send email from my localhost to other people. What do I need to do that?

For example do I need to install mailserver? If I'm not mistaken there's is a language that you don't need a mailsever to send email. Is it right?

Inside the PHP.ini, there is [mail function]. How to configure this? I checked on the Internet, but do not really understand how it works.

[mail function] ; For Win32 only.
SMTP = localhost
smtp_port = 25

sendmail_from [email protected] //Not sure how to write this?
A: 

mail("[email protected]", "Subject", "This is an email!");

You just need to install some email server. If you are on linux, you can try exim, if you are on windows, you can use the SMTP server that comes with IIS.

webdestroya
Don't forget that not all versions of Windows have IIS, and some that do don't have it installed. I believe XP Home did not have it on the install disc.
patricksweeney
XP Pro has it, XP Home isn't meant to be a server system.
webdestroya
Exactly, but you would be surprised how many forum posts i've seen over the years of people asking why they didn't have it.
patricksweeney
Ah yea. I figured if he is sending out emails, he should be doing it from a server system, and not from his home computer. But good point +1
webdestroya
+2  A: 

You would have to set up a local mail server if you want to send mail using the mail() function. You can't use a remote mail server as the php mail() function does not allow you to specify authentication credentials. However, I have found setting up a local mail server tedious and annoying, in addition it can be dangerous. I recommend looking into PHPMailer. It is simple to use and get running.

patricksweeney
A: 

Yes, you do need a mail server available. PHP's mail() function accepts the information you give it and passes it off to the mail server for delivery. PHP doesn't deliver mail itself.

What mail server you use depends on what operating system you are using. Traditionally on unix-type machines there will be an installation of sendmail or some other service running. On Windows, you can specify the name of an SMTP server in the php.ini configuration file.

Timothy
A: 

The simple way is by using the mail() command. On Linux it's a pipe to sendmail binary and on Windows, I don't know, probably it use some Microsoft voodoo library.

Anyway, I strongly recommend to use phpMailer because it's a mature project, really stable, easy to setup, with a lot of features and it also includes an SMTP and IMAP client implementation, so absolutely cross-platform.

Anyway, you should consider to use anyway a local SMTP server as first hop to handle the mail queue in case of network failure.

Cesar
+1  A: 

You need the software that will actually send the email after your PHP script has made a request to so (through using the mail function: http://php.net/mail). As stated in some of the previous responses there are software options for this, regardless of what operating system you run.

This, however, can sometimes be quite tricky for a beginner. Typically your ISP will give you access to an SMTP server from which to send emails, and you can set up your configuration to do this. For development purposes, this ought to do the trick for you. These details will likely be on your ISP's website (or possibly in your email client, somewhere.) Your config would end up looking something like

[mail function] ; For Win32 only.
SMTP = smtp.my-isp.com
smtp_port = 25
sendmail_from [email protected]

Failing that, you could just upload your script to your web host, where it should already be configured to work.

Hope that helps.

icio
A: 

phpmailer is a good choice. you can google it for details. Actually, email is sent using socket.

A: 

There is no need for an installation of a special module to have access to mail functions in PHP. But For the Mail functions to be available, PHP must have access to the sendmail binary on your system during compile time. If you use another mail program, such as qmail or postfix, be sure to use the appropriate sendmail wrappers that come with them. PHP will first look for sendmail in your PATH, and then in the following:

/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib. 

It's highly recommended to have sendmail available from your PATH. Also, the user that compiled PHP must have permission to access the sendmail binary.

If you are working on a linux environment using a hosting provider is most likely that the sendmail is already present, otherwise you can check from a terminal doing:

cat some_file.txt |mail -s "test mail" [email protected]
Elzo Valugi