简体   繁体   English

从本地主机发送邮件

[英]Send mail from localhost

I want to know if it is possible to send emails from localhost. 我想知道是否可以从本地主机发送电子邮件。 If yes, how? 如果是,怎么办? I want to send emails from my localhost using my gmail account. 我想使用gmail帐户从本地主机发送电子邮件。 I have a Mac OS X Yosemite Version 10.10.1 and I am running XAMPP 5.6.3-0. 我有Mac OS X Yosemite版本10.10.1,并且正在运行XAMPP 5.6.3-0。

Thanks! 谢谢!

You can use PHP mailer and not configure SMTP on your machine or you can follow this instructions to configure sendmail with GMAIL . 您可以使用PHP邮件程序而不在计算机上配置SMTP,也可以按照以下说明使用GMAIL配置sendmail。 I like option 2 :) (Just for fun). 我喜欢选项2:)(只是为了好玩)。 Of course the first option is easier. 当然,第一种选择更容易。

  1. First go to the path that you installed Xampp application. 首先转到您安装Xampp应用程序的路径。 By default it is C:\\xampp\\ . 默认情况下为C:\\xampp\\
  2. Then we need to find the php.ini file which contains the configurations belong to PHP. 然后,我们需要找到php.ini文件,其中包含属于PHP的配置。 This file by default is located at C:\\xampp\\php\\php.ini . 默认情况下,此文件位于C:\\xampp\\php\\php.ini Open it using any text editor like notepad. 使用任何文本编辑器(如记事本)将其打开。
  3. Using search in the editor try to find sendmail_path . 在编辑器中使用搜索尝试查找sendmail_path There should be two of them. 应该有两个。 One is commented using a ; 一个用注释; (semicolon) in the beginning of the line , and the other one is not commented. (分号)在行的开头,而另一个未注释。 Comment the one that is active and active the one is commented. 注释一个处于活动状态的活动,而一个活动被注释。 After the edit it should looks like below... (Similar) sendmail_path = "\\"C:\\xampp\\sendmail\\sendmail.exe\\" -t" ; XAMPP: Comment out this if you want to work with mailToDisk,... ;sendmail_path="C:\\xampp\\mailtodisk\\mailtodisk.exe" 编辑后,它应该如下所示(类似) sendmail_path = "\\"C:\\xampp\\sendmail\\sendmail.exe\\" -t" ; XAMPP: Comment out this if you want to work with mailToDisk,... ;sendmail_path="C:\\xampp\\mailtodisk\\mailtodisk.exe" sendmail_path = "\\"C:\\xampp\\sendmail\\sendmail.exe\\" -t" ; XAMPP: Comment out this if you want to work with mailToDisk,... ;sendmail_path="C:\\xampp\\mailtodisk\\mailtodisk.exe"
  4. Save the php.ini file and restart the Apache process. 保存php.ini文件并重新启动Apache进程。 This is necessary for the configuration to take place. 这对于进行组态是必需的。
  5. Next navigate to the sendmail directory. 接下来导航到sendmail目录。 By default it should be located at C:\\xampp\\sendmail and open the sendmail.ini in the text editor. 默认情况下,它应该位于C:\\xampp\\sendmail并在文本编辑器中打开sendmail.ini
  6. Now we need to set the configuration for the mail server. 现在我们需要设置邮件服务器的配置。 For this case I chose Gmail. 对于这种情况,我选择了Gmail。 The SMTP address of Gmail is: smtp.gmail.com and the SMTP port for Gmail is 587 . Gmail的SMTP地址为: smtp.gmail.com ,Gmail的SMTP端口为587
  7. Find smtp_server and write the Gmail SMTP address in front of that. 找到smtp_server并在其前面写下Gmail SMTP地址。
  8. Find smtp_port and write the Gmail SMTP port in front of that. 找到smtp_port并在其前面写入Gmail SMTP端口。
  9. Scroll down , you should be able to see auth_username & auth_password . 向下滚动,您应该能够看到auth_usernameauth_password Put your gmail username in front of auth_username and put the password in front of auth_password . 将您的gmail用户名放在auth_username前面,然后将密码放在auth_password前面。
  10. Save and now you are good to send mail from local host. 保存,现在您可以从本地主机发送邮件了。

    • Note that your PHP mail function should have "from" header,otherwise your mail will not go through. 请注意,您的PHP邮件功能应具有“ from”标头,否则您的邮件将不会通过。
    • Also remember the that the destination will receive the mail from your Gmail address not from the address you put in your PHP code. 还要记住,目的地将从您的Gmail地址接收邮件,而不是从您在PHP代码中输入的地址接收邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM