Send email SMTP from localhost with WAMP setup

流过昼夜 提交于 2019-12-11 09:00:35

问题


I'm trying to configure my php.ini file so I can send emails from 'localhost' in my dev environment using PHP. I no longer have access to an open SMTP server, and Gmail no longer works with their new SSL setup. I've done a lot of research and seen lots of "solutions" here and elsewhere, but they don't work. I've tried installing local SMTP servers (hMailServer asks for a password to install, Free SMTP Server doesn't work, etc).

Does anyone know of a free SMTP server I can setup in my php.ini file, or any other way to send mail from localhost (I just need it for testing purposes). I don't want to have to change code and send emails in a completely different way when I switch to production. (I'm using Zend and the Zend_Mail class)


回答1:


In windows I was usually using Mercury to sent emails from localhost for testing purposes. Mercury is free for non-commercial use and it is also used in xampp.




回答2:


You could try using Zend_Mail_Transport_File for testing instead.

$mail = new Zend_Mail();
$mail->send(new Zend_Mail_Transport_File());



回答3:


Solution for XAMP, WAMP or etc..

download hMailServer; Then configure program:

  1. When you first open hMailServer Administrator, you should add new domain.
  2. Click on the "Add Domain ..." button at the Welcome page.
  3. Under the domain text field, enter your computer's IP, in this case it should be 127.0.0.1.
  4. Click on the Save button.
  5. Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
  6. Enter "localhost" in the localhost name field.
  7. Click on the Save button.

If you need to send mail using a FROM addressee of another computer, you need to allow deliveries from External to External accounts. To do that, follow these steps:

  1. Go to Settings>Advanced>IP Ranges and double click on "My Computer" which should have IP address of 127.0.0.1
  2. Check the Allow Deliveries from External to External accounts checkbox.
  3. Save settings using Save button.

If you use Gmail account, then need small modification :

  1. Go to Settings>Protocols>SMTP and select "Delivery of Email" tab
  2. Enter "smtp.gmail.com" in the Remote Host name field.
  3. Enter "465" as the port number
  4. Check "Server requires authentication"
  5. Enter your Google Mail address in the Username field
  6. Enter your Google Mail password in the password field.
  7. Check "Use SSL"



回答4:


You will have to use this confuguration for the transport of the mail

$transport = new Mail\Transport\Smtp();  
        $options = new Mail\Transport\SmtpOptions (array(  
                    'name' => 'host',  
                    'host' => 'smtp.gmail.com',  
                    'port'=> 587,  
                    'connection_class' => 'login',  
                    'connection_config' => array(  
                        'username' => "yourGmailUserMail",  
                        'password' => 'yourGmailPassword',  
                        'ssl'=> 'tls',  
                    ),  
        )); 
        $transport->setOptions($options)

;

and it will works.



来源:https://stackoverflow.com/questions/4818444/send-email-smtp-from-localhost-with-wamp-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!