Can't Send Email from PHP Script on Macbook Pro M1 Webserver

I have a PHP-based website running on a remote Linux webserver that sends email fine, but my development machine is a Macbook Pro M1 which I've set up as a webserver using Homebrew Apache/httpd/nginx. Everything works fine except email. I use the PHP mail function.


If I understand correctly, mail on MacOS is handled by postfix (the MacOS mail app depends upon an outside service like gmail or the cloud). Using terminal as superuser I checked the postfix status:


% postfix status

postfix/postfix-script: the Postfix mail system is not running


So I started it up:


% postfix start

postfix/postfix-script: starting the Postfix mail system

% postfix status

postfix/postfix-script: the Postfix mail system is running: PID: 29329


I next tested mailx on the terminal command line, but that didn't work either:


% echo "Hello World" | mailx -s "Test email mailx" email@evcforum.net


I also tried sendmail, which also didn't work:


% echo "Subject: Email Test

>

> Email Body" | sendmail email@evcforum.net


The above works fine from a bash shell on my Linux server.


I searched the Internet for solutions, and not finding any I contacted Apple Support. They said that while they'd like to help, this was outside of their range of support, so I'm checking here to see if anyone can help me send email, first from the terminal command line, but eventually from PHP.


I have a related problem where I cannot make postfix start at boot time. The "launchctl list" command lists a couple postfix daemons, and I issued these commands:


% launchctl enable system/com.apple.postfix.master

% launchctl enable system/com.apple.postfix.newaliases


But upon reboot postfix is not running:


% postfix status

postfix/postfix-script: the Postfix mail system is not running


So I need some help with launchctl and the postfix daemons, too.


[Email Edited by Moderator]

MacBook Pro Apple Silicon

Posted on Aug 30, 2022 8:16 AM

Reply
7 replies

Sep 4, 2022 5:39 AM in response to BobTheFisherman

Thanks for the reply. That was one of the first pages I visited, and unfortunately no, that doesn't work. I also read that mailx can be used, so I also tried this:


% echo "Hello World" | mailx -s "Test email" email@evcforum.net                                                                                      

% mailq                                                                                                                  

Mail queue is empty


But no email arrives.

Sep 4, 2022 6:42 AM in response to elkind00

elkind00 wrote:

my development machine is a Macbook Pro M1 which I've set up as a webserver using Homebrew Apache/httpd/nginx. Everything works fine except email.

Whoa! Whoa! Full stop, horsey!

If I understand correctly, mail on MacOS is handled by postfix (the MacOS mail app depends upon an outside service like gmail or the cloud).

I'm impressed. This is your first post and you are deep, deep into Black Magic.


This is a really long, and really complicated story. To make it short, all you need to do is configure it. That is left as an exercise for the reader.


Many years ago, I started posting a series of User Tips on Setting up a local web server on a Mac


Back then, I was still using MySQL and I had setup my Mac to send local e-mail. I wrote a User Tip about that too: Local mail server for OS X - Apple Community


Pay close attention to the date - 2013. I have no idea what changes have taken place since then. I'm sure it hasn't gotten any easier.


It is a much different world today than in 2013. Deploying web sites is radically different. I strongly encourage you to 1) drop PHP, and 2) look at AWS services. Pretty much anything else is just making more trouble for yourself.


Sep 4, 2022 3:44 PM in response to etresoft

Not my first rodeo, just the first time I've posted here. Thanks for the information, I've just started looking at it.


I didn't realize that email from the terminal command line didn't just work by default. I just figured my Macbook wasn't configured properly, that someone would tell a few lines to change in the postfix main.cf file and I'd be on my way.


About your suggestion to drop PHP, I'm curious why, but I've been making noises about a redesign for a few years. But there's a lot of website code now, around 50,000 lines including js. It happened gradually - I started the website in 2000. People have encouraged me to look at react and bootstrap, but I haven't gotten around to it yet. I've been trying to clean up just a few things I was never happy with before moving on, including one feature that uses PHP email and that I'd prefer to test on my development machine before releasing it to the website.


I looked at AWS maybe five years ago and it was way out of my price range, but looking at it now I see how they package things has changed (a lot!), and maybe it would be cheaper for my particular needs now. But looking at their website I wasn't able to figure out how much a webserver/apache/mysql/control-panel/security-features/mail-with-good-spam-control combo might cost. I did find a webpage that estimated that a typical MERN website would cost $20/month, which is a great price, but there was no information about control panels. I prefer using a control panel because they do most of the work of creating a website, managing email, and handling security - I use Plesk right now, but I"m not picky. Probably the best thing to do would be to create an AWS copy of my website and play around with it.

Sep 4, 2022 5:57 PM in response to elkind00

elkind00 wrote:

someone would tell a few lines to change in the postfix main.cf file and I'd be on my way.

That link I posted above identifies those lines, circa 2013.

About your suggestion to drop PHP, I'm curious why, but I've been making noises about a redesign for a few years. But there's a lot of website code now, around 50,000 lines including js. It happened gradually - I started the website in 2000. People have encouraged me to look at react and bootstrap, but I haven't gotten around to it yet. I've been trying to clean up just a few things I was never happy with before moving on, including one feature that uses PHP email and that I'd prefer to test on my development machine before releasing it to the website.

It's just a dead end. There are still plenty of people using it, but you won't find anyone in the future who wants to work on it. I'm not really familiar with large scale web frameworks. There are many of then. The last time I was doing anything like that was several years ago, and PHP was long since out of favour back then. These days, people do most of the work on the front end, using one of 217 javascript frameworks. The backend can be just about anything, other than PHP. 😄 But these days, the backend is probably Node serving JSON.

I looked at AWS maybe five years ago and it was way out of my price range

You just have to be careful. You can get a tremendous amount of services for literally free. Or you can pay $1000/month for an empty database.

But looking at their website I wasn't able to figure out how much a webserver/apache/mysql/control-panel/security-features/mail-with-good-spam-control combo might cost.

Maybe start with Lightsail. It is a good way to get started with AWS. You get all the standard VPS stuff for a flat fee. Then, you can start adding pieces of the real AWS in. Before long, Lightsail is holding you back and you have found better solutions like Lambda.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't Send Email from PHP Script on Macbook Pro M1 Webserver

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.