Sending email from localhost

2019-01-09 13:41发布

问题:

I'm using WampServer on Windows to test a site. I have a registration system where users get a confirmation email.

Is it possible to send emails from a localhost?

回答1:

If you want to send emails from localhost directly, you need to install a Mail Transport Agent (MTA), or if you like, a SMTP service.

IIS provides one. You can otherwise find some others on Google.

You can also change your php.ini mail settings. This won't use localhost per say to send emails, but a relay host that will allow you to send emails from a PHP script.



回答2:

Not unless you install a SMTP server on it. I think XAMPP includes one, but you're probably better off just using an existing external server. You can set this with the php.ini SMTP setting.



回答3:

I actually just set this up the other day using fake sendmail.

It is actually fairly easy to set up. I found this tutorial to be helpful.

There are other alternatives out there but this is working great for me using Gmail.

I can use the mail() function in PHP without issues. One issue that I haven't resolved yet is that the email always appears to come from my gmail address instead of whatever I supplied in the mail() arguments. I believe this may be a Gmail feature, not a sendmail issue though.



回答4:

It's quite simple. (Adapt syntax for your convenience)

public $smtp = array(
    'transport' => 'Smtp',
    'from' => 'your_email@gmail.com',
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'your_email@gmail.com',
    'password' => '*****'
)