PHP: how to send email basics

前端 未结 7 1175
滥情空心
滥情空心 2021-01-28 18:05

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

相关标签:
7条回答
  • 2021-01-28 18:28

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

    0 讨论(0)
  • 2021-01-28 18:33

    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 =my.account@my-isp.com
    

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

    Hope that helps.

    0 讨论(0)
  • 2021-01-28 18:36

    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" user@yourmail.com
    
    0 讨论(0)
  • 2021-01-28 18:42

    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.

    0 讨论(0)
  • 2021-01-28 18:43

    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.

    0 讨论(0)
  • 2021-01-28 18:46

    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.

    0 讨论(0)
提交回复
热议问题