How to have my PHP Send mail? Ask Question Asked 8 years, 8 months ago. The program to be used is defined by the configuration settings in the php.ini file. Now make sure that your php.ini has correct sendmailpath. It should read as.
![]() Changelog![]()
November 15, 2016
Update instructions to work on macOS Sierra. Fix bug with deleting older saved eml files. What is this?
You may already know this feeling. You've spent a few hours developing a shell script to send out billing emails to customers and after pressing 'enter' you suddenly realise that your script is sending out hundreds of dummy emails to your customers (you had copied some data from the live server 'just to test things out a bit').
You quickly stop the script, but the damage is already done! You're now getting confused emails from your customers... time to start writing that apology email!....... OR... you could implement a testing mail server so this situation NEVER HAPPENS AGAIN!
How does it work?
Why should I use this?
How do I install it?
Open a terminal window and copy and paste the following...
Now you've got the output folder created and the smtp_catcher.php script installed, you just need to update your php.ini and set some permissions.
NB. If your php binary is not in
/usr/bin/php then you will need to edit the first line of smtp_catcher.php.
Configure PHP to pipe emails to the smtp_catcher.php script
Open up your php.ini file and find the following line. Please note, if you have a separate php.ini file for your CLI binary, you'll need to edit that one as well.
Change it to the following (replacing
<your_username> with your macOS username).
Save your changes and restart your webserver.
Give permission to PHP to open Apple Mail![]()
PHP runs as the
_www user by default, which will mean smtp_catcher.php won't be able to open your GUI mail program, so we have to give sudo access to the _www group. If you are not using the Apache/PHP that comes pre-installed in Mac OS X, then you may need to change _www to suit your needs. Mac OS X versions prior to macOS Sierra should use www instead of _www .
Add the following line to the sudoers file and save (replacing <your_username> with... yep, your username).
This will now give permission to PHP to execute the smtp_catcher.php script with sudo permissions, without having to enter a password!
Test it to make sure everything works
The final step is to create and execute a test script, which can be as simple as this.
What if I'm using PHP on Windows?
Easy! Install the Test Mail Server Tool and uncomment the following lines from your
php.ini , and restart your webserver.
How do you get sendmail to work with php? I searched this forum for topics with sendmail in them and somebody noticed that during an OSX update, the permissions for / are changed. I followed the instructions: chmod g-w / /usr/sbin/sendmail -bd -q1h I then changed my /usr/local/lib/php.ini file to use /usr/sbin/sendmail as the sendmail_path. I restared apache using the web sharing control panel and tried to send am email with a php script. No luck. The script didn't give me any errors. I used Mail.app and changed my sendmail location to 'localhost'. I then sent myself an email. I recieved the email which lead me to believe that sendmail is working fine. The headers of the email says: Received: from localhost (localhost.nycap.rr.com [127.0.0.1]) by localhost.nycap.rr.com Any help would be greatly appreciated. Thanks. ![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |