2014-03-14 214 views
17

我找到正确的信息关于如何本地主机WAMP发送电子邮件。以及如何获得授权从特定授权电子邮件地址发送电子邮件以发送任何其他电子邮件地址。如何从本地WAMP服务器发送电子邮件发送电子邮件Gmail Hotmail等?

如何配置这整个步骤解释我细节,我已经在这里参观一些堆栈溢出回答以及博客文章,但都是非常混乱和老过时,所以它可能不工作。所以我需要Stack Overflow用户的帮助。谢谢。

+1

你不能从你的本地主机发送电子邮件。它需要smtp。 –

+0

如何获取SMTP –

回答

17

localhost配置工作电子邮件客户端是很繁琐的事,我已经花了挫折小时尝试它。最后我发现这种方式来发送邮件(使用WAMP,XAMPP等):

安装hMailServer

配置此设置hMailServer:

  1. 打开hMailServer管理员。
  2. 单击“添加域...”按钮创建一个新域。
  3. 在域文本字段下,输入您的计算机的本地主机IP。
    • 例如:127.0.0.1是您的本地主机IP。
  4. 点击 “保存” 按钮。
  5. 现在转到设置>协议> SMTP并选择“邮件发送”选项卡。
  6. 找到localhost字段输入“localhost”。
  7. 点击保存按钮。

配置您的Gmail帐户,进行以下修改:

  1. 进入设置>协议> SMTP,然后选择 “邮件的发送” 选项卡。
  2. 在远程主机名称字段中输入“smtp.gmail.com”。
  3. 输入“465”作为端口号。
  4. 选中“服务器需要验证”。
  5. 在用户名字段中输入您的Google Mail地址。
  6. 在密码字段中输入您的Google Mail密码。
  7. 选中标记“Use SSL”
  8. 保存所有更改。

可选

如果你想从你需要通过下面的步骤,以允许从外部到外部帐户交付另一台计算机发送电子邮件:

  1. 进入设置>高级> IP范围并双击“我的电脑”,其中 应具有IP地址127.0.0.1
  2. 检查允许从外部到外部交付acc数量复选框。
  3. 使用保存按钮保存设置。
+1

我应该知道如何在php脚本中使用此...配置后 – 151291

+0

但请记住,没有像样的真正的邮件服务器会接受你的邮件,因为你看起来更像是一个垃圾邮件发送者而不是一个明智的质量邮件服务器。 – RiggsFolly

2
a) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMP or LAMP server. Note : Make a backup of php.ini file 

b) Search [mail function] in the php.ini file. 

You can find like below. 
[mail function] 
; For Win32 only. 
; http://php.net/smtp 
SMTP = localhost 
; http://php.net/smtp-port 
smtp_port = 25 


; For Win32 only. 
; http://php.net/sendmail-from 
;sendmail_from = [email protected] 


Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25. Change sendmail_from from [email protected] to your domain email address which will be used as from address.. 

So for me, it will become like this. 
[mail function] 
; For Win32 only. 
SMTP = smtp.planetghost.com 
smtp_port = 25 
; For Win32 only. 
sendmail_from = [email protected] 
auth_username = [email protected] 
auth_password = example_password 


c) Restart the XAMPP or WAMP(apache server) so that changes will start working. 

d) Now try to send the mail using the mail() function , 

mail("[email protected]","Success","Great, Localhost Mail works"); 

credit

================================= ===============================================

另一种方式

Gmail服务器在SSL下使用SMTP身份验证。我认为这是没有办法用在该情况下mail()函数,所以你可能要检查这些替代品:

  1. PEAR: Mail
  2. phpMailer

它们都支持SMTP认证下SSL。

信用:Check reference answer here

+0

我试试这个方法来配置 –

+0

你是否意味着你已经尝试过? –

+0

不,目前我按照此步骤进行配置.. –

0

以下是使用PHPmailer库发送电子邮件的最佳方式,这是唯一适用于我的方法。

require_once 'mailer/class.phpmailer.php'; 
    $mail = new PHPMailer(); // create a new object 
    $mail->IsSMTP(); // enable SMTP 
    $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only 
    $mail->SMTPAuth = true; // authentication enabled 
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail 
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 465; // or 587 
    $mail->IsHTML(true); 
    $mail->Username = "[email protected]"; 
    $mail->Password = "xxxxxxx"; 
    $mail->SetFrom("[email protected]"); 
    $mail->AddAddress($to); 
    $logfile = dirname(dirname(__FILE__)) . '/mail.log'; 
    try { 
     $mail->Body = $message; 
     $mail->Subject = $subject; 


     file_put_contents($logfile, "Content: \n", FILE_APPEND); 
     file_put_contents($logfile, $message . "\n\n", FILE_APPEND); 

     if(!$mail->Send()) { 
      echo "Mailer Error: " . $mail->ErrorInfo; 
     } else { 
      echo "Email has been sent"; 
     } 
    } catch (Exception $e) { 
     #print_r($e->getMessage()); 
     file_put_contents($logfile, "Error: \n", FILE_APPEND); 
     file_put_contents($logfile, $e->getMessage() . "\n", FILE_APPEND); 
     file_put_contents($logfile, $e->getTraceAsString() . "\n\n", FILE_APPEND); 
    } 
+0

我可以在哪里下载邮件程序以及你正在使用的邮件程序功能? – 151291

+0

@ 151291 https://packagist.org/packages/phpmailer/phpmailer – kjdion84

0

以下是使用Sendmail通过wamp服务器从本地主机发送电子邮件的步骤。

  1. 首先,你需要下载Sendmail的zip文件link
  2. zip文件解压缩,并把它放在C:\ WAMP
  3. 现在,你需要编辑Sendmail.iniC:\wamp\sendmail\sendmail.ini
smtp_server=smtp.gmail.com 
smtp_port=465 
[email protected] 
auth_password=your_password 
  • 访问您的电子邮件帐户。点击齿轮工具>设置> 转发和POP/IMAP> IMAP访问。点击“启用IMAP”,然后 保存您的更改
  • 运行您的WAMP服务器。在Apache模块下启用ssl_module。
  • 接下来,在PHP下启用php_openssl和php_sockets。
  • **现在重要部分打开php。INI文件上"C:\wamp\bin\php\php5.5.12\php.ini""C:\wamp\bin\apache\apache2.4.9\bin\php.ini"设置sendmail_path **
  • sendmail_path = “C:\瓦帕\ sendmail的\ sendmail.exe -t”

  • 重新启动Wamp服务器。
  • 它肯定会奏效。

    7

    对我来说Fake Sendmail的作品。

    怎么办:

    1)编辑C:\wamp\sendmail\sendmail.ini:

    smtp_server=smtp.gmail.com 
    smtp_port=465 
    [email protected] 
    auth_password=your_password 
    

    2)编辑php.ini并设置sendmail_path

    sendmail_path = "C:\wamp\sendmail\sendmail.exe -t" 
    

    就是这样。现在你可以测试一封邮件。

    0

    没有任何SMTP服务器发送邮件,使用此代码发送邮件....

    click below for mail sending code 
    

    Click here

    听人首先,你可以做到这一点不太安全的Gmail帐户发送邮件后与您的Gmail帐户

    您可以使用此php.ini设置

    ;smtp = smtp.gmail.com 
    ;smtp-port = 25 
    ;sendmail_from = my gmail is here 
    

    而sendmail.ini设置

    smtp_server = smtp.gmail.com 
    smtp_port = 465 
    smtp_ssl = auto 
    auth_username = my gmail is here 
    auth_password = password 
    hostname = localhost 
    
    you can try this changes and i hope this code sent mail.... 
    
    0

    如果你有WAMP的设置,不会发邮件,只有一对夫妇的事情要做。 1.找出你的isp的smtp服务器名称。 Gmail的东西是最有可能带来不必要的复杂 2.创建这样在你的“www”文件夹和编辑一个文件phpsetup.php:

    <?php 
        phpinfo(); 
    ?> 
    

    这会给你什么WAMP使用手柄。 3.搜索php.ini文件。有可能是多余的。你想要的那个是影响上面文件输出的那个。 4.在最可能的php.ini中找到smtp地址。 5.输入您的浏览器localhost/phpsetup.php并向下滚动到smtp设置。它应该说'localhost' 6.编辑php.ini文件smtp设置为您的ISPs smtp服务器的名称。 检查它是否为您更改phpsetup.php。如果它工作完成,如果没有,你正在处理错误的文件。

    这个问题应该在Wordpress网站上,但他们太过自己或者试图获得客户。;)

    相关问题