Test emails locally with mamp

谁说我不能喝 提交于 2019-11-29 01:11:34

问题


First thing first, i'm totally new to this kind of localhost server setup and i've been spending the last couple of days trying to figure this out, but with no luck.

I'm developing a php website with an email form.

I'm on a MAC using codekit and MAMP FREE and everything works fine. Now my question is, is it possible to test the email that should be sent from the form locally?

I've tried a lot of examples, like uncommenting the [mail function] bit in php.ini file, installing 3rd parties app like fakeSMTP and MockSMTP but absolutely nothing worked. The mailto() code should work, as when i debug it no error are thrown

Is it possible to do that or not? anyone who knows how to properly set this up or that can point me to a dumb-proof guide?


回答1:


Ok, if someone is interested in this, i finally found a way to make it work.

I'm gonna explain it here in a detailed step-to-step tutorial.

Requirements

  • MAMP pro
  • working gmail account cause you actually need to login to the email account inbox (I made it work using gmail, not sure about others)

Step-by-step tutorial

  • First thing first, you need to install mamp pro. In the postfix tab, add gmail.com as domain for outgoing emails and then click the button "Use this data"
  • After this is done, you want to open the terminal and type in sudo nano /System/Library/LaunchDaemons/org.postfix.master.plist (this will allow you to edit the org.postfix.master.plist file otherwise not editable.

  • The only edit that you want to do is adding at the top, right after <dict>, this line <key>Disabled</key>

  • Now close the terminal and restart your mac.

  • After the restart, open MAMP and go to the website you want to test the emails and submit the email.

NB: It is important that you use a working account for the to section of the mail() function, otherwise you won't be able to test the emails!

  • Nothing happens in the front end, but if you now open MAMP -> postFix tab, at the botto you can see the path of the log file and an arrow, click on the arrow and it will display a log message.
  • Scroll down till the last line, where you should find something saying status:sent. This status sent means that the email has been sent and that the local test worked as expected

What's next?

  • Ok, now login to your gmail account (the one you used for the to section in your mail() function
  • Go to spam and you should see the email that you just sent from your local machine.

I'm using it, and it is actually working nicely.

Quick tip

After this, I made a couple of adjustment in my gmail inbox, adding an alias and a filter. I'm gonna explain this as well as it may be useful for a beginner

  • Login to you gmail account from your pc
  • go to the top right cog icon and then go to settings
  • In accounts and import, add another account to use as alias (in my case is [myemailaddress]+test@gmail.com)
  • Once this is done, go to filters tab
  • Add a new filter and set it up to affect all the emails to [myemailaddress]+test@gmail.com
  • Click continue to go to the next screen
  • Now, here you can actually tweak it as you prefer, but the important thing is to check never send it to spam so that you will always be able to see the emails that you'd like to test. (my personal setup is to skip the inbox (archive) and add a specific label)

That's it! hope this is clear enough and that it will help some of you.



来源:https://stackoverflow.com/questions/30616766/test-emails-locally-with-mamp

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