I have set up a LAMP server with sendmail on Ubuntu 14.04.
When sending mail, either from terminal or PHP mail(), it won't work properly.
When I use mail("user#localhost","test","test"); it sends it correctly, and I can read the message with mail from terminal, but when sending to Gmail address, message won't go trough.
Same outcome when using "test" | mail -s "test" xyz#gmail.com" from server terminal.
Any idea how to fix this?
I have been Googling for several hours now, I have tried everything without finding working solution, and I'm starting to lose hope.
If you're running Ubuntu here is a much simpler solution:
issue from command line >
apt-get install ssmtp
Then edit the configuration file in /etc/ssmtp/ssmtp.conf
A sample configuration to use your gmail for sending e-mails:
# root is the person who gets all mail for userids < 1000
root=your#email.com
# Here is the gmail configuration (or change it to your private smtp server)
mailhub=smtp.gmail.com:587 (leave this the way it is)
AuthUser=your#gmail.com (just change this)
AuthPass=yourGmailPass (and change the password for your gmail account)
UseTLS=YES (leave this the way it is)
UseSTARTTLS=YES (leave this the way it is)
Note: Make sure the "mail" command is present in your system. mailutils package should provide this one in Debian based systems.
Then try send emails again, send it to another domain #gmail, #aol, #yahoo, #privatedomain besides localhost email addresses.
There're tons of possible problems, so you need to get some logs of error that happening.
Most probably, Google just rejects your email as your server is not correctly configured.
Related
I am setting up the dev environment on the M1 MBP. The PHP and NGINX are installed with the HomeBrew directly on the machine. The ElasticSearch and MailHog - with the Docker.
I am struggling to see the email in the MailHog web interface after I send one through from the PHP file. The project is working and my local PHP and NGINX communicates with the Dockerised ElasticSearch well, so I am sure MailHog is "installed" properly; I see the interface on my web on port 8025 as well.
I've played around with the php.ini file (/opt/homebrew/etc/php/7.4/php.ini). I've double checked that ini file is the one that is used for the project (verified it with changing memory_limit value. I've updated the Postfix (/etc/postfix/main.cf) configuration with the following configuration too:
# For MailHog
myhostname = localhost
relayhost = [localhost]:1025
...and reloaded it like this sudo postfix reload.
My /etc/hosts file has this line: 127.0.0.1 l.month db elasticsearch mail; and pinging them all works too.
When I keep the php.ini file line (containing the sendmail_path) commented out the mail function in PHP script works; but the email is sent directly to my real email address, not the MailHog. If I uncomment it and set it to sendmail_path = /usr/sbin/sendmail -S mail:1025 then the mail function from PHP is returning false. I don't understand why, since this value is advised to be used from this source. However if I use the sendmail_path = /usr/sbin/sendmail -t -i PHP again works, but the MailHog doesn't intercept anything. I've double checked that the real path for the sendmail is /usr/sbin/sendmail by executing the command which sendmail.
I also played around with the SMTP value and the smtp_port (in same ini file); I changed values from localhost to 127.0.0.1 and mail; and the 25 to 1025 respectively. I didn't forget to restart my PHP service after each change either.
Furthermore, I experimented with the postfix configuration values by changing localhost to 127.0.0.1 and mail (as well as reloading it) as well; no luck.
To make sure I tried all of it, I also logged out and logged in to my account to make sure the changes take place; no luck again.
I assume that I do not need the mhsendmail file on my local if I have the docket container running, so I never installed it, hoping it is in the docker container; otherwise, then what's the point of the container after all? If I am wrong with my assumption, please let me know.
Regarding logs, no errors are shown; only this message:
[05-Aug-2022 13:11:24 UTC] mail() on [/Users/[path_here]]src/pub/mail.php:3]: To: my#email.com -- Headers: -- Subject: Test Subject
FireWall is disabled on the machine.
Please help me solve my problem so that I could see the email send from the PHP in the MailHog web interface. Thanks!
I found the issue. Found because decided to go with the workaround - downloaded the MailHog with the HomeBrew instead of using Docker. But it didn't work! I realised I forgot to download the mhsendmail since I am using the local MailHog.
Then it hit me! I googled this: do i need to install mhsendmail if I use docker. And I got the answer: No, mhsendmail is not included in the mailhog/mailhog docker container. You will need to download mhsendmail (by either curl or go get) in the container that you are planning to send email from.
So apparently I was wrong to assume that MailHog comes with the mhsendmail binary.
It started to work when I downloaded one and updated the postfix config file to:
myhostname = localhost
relayhost = [127.0.0.1]:1025
I didn't even need to touch the php.ini! The sendmail line can stay commented out!
I hope this answer helps others as well!
I'm trying to use Zoho's SMTP servers to send registration emails from a MyBB installation. However, the emails are never sent and when I check the logs I notice that the error is.
Month Day Year:Hour:Minute host=smtp.zoho.com tls=on auth=on user=user[at]mydomain.com from=user[at]mydomain.com recipients=some.user[at]gmail.com smtpstatus=553 smtpmsg='553 Relaying disallowed' errormsg='the server did not accept the mail' exitcode=EX_UNAVAILABLE
(Some parts were masked to hide private information!)
This is the sendmail path set in php.ini
sendmail_path = "/usr/bin/msmtp -C /etc/msmtp/myserver --logfile /var/log/msmtp/myserver.log -a default -t"
(Some parts were masked to hide private information!)
This is the myserver configuration for MSMTP
# Define here some setting that can be useful for every account
defaults
logfile /var/log/msmtp/general.log
# Settings for default account
account default
protocol smtp
host smtp.zoho.com
tls on
tls_starttls off
tls_certcheck off
port 465
auth plain
user user[at]mydomain.com
password **********
from user[at]mydomain.com
logfile /var/log/msmtp/myserver.log
# If you don't use any "-a" parameter in your command line,
# the default account "default" will be used.
# account default: default # (disabled because this gives a "redefined" error)
(Some parts were masked to hide private information!)
The problem is that I know it's working and that no ports are blocked because when I use the same command in the command line. The email is successfully sent and received.
sudo echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" | msmtp --debug -a default --from=user[at]mydomain.com -t some.user[at]gmail.com --file=/etc/msmtp/myserver
(Some parts were masked to hide private information!)
Which means that it's either something wrong with the way MyBB sends emails or it's something wrong with my PHP configuration or command line that I have set in php.ini file.
I've searched this all day but every result that I get is either not related to PHP or it never worked from the beginning. And mine is working from the command line but not from PHP.
I use UFW on the server and every port is completely opened so I'me guessing it's not related to blocked ports.
It worked with Gmail but every email was sent to spam folder and it didn't worked every time with every email.
EDIT:
I've tried to send an email with PHP5-CLI and it worked. So I'm guessing that it's either something wrong with PHP5-FPM or MyBB.
I can't test this without a MyBB install, but if it uses the native PHP mail function, you may need to add the -f option to the mail() function call since you are using sendmail.. Note it is the 5th parameter (I wasted a day once thinking it the was 4th)
mail('nobody#example.com', 'the subject', 'the message', null,
'-flocaluserr#thisdomain.com');
Currently I have a mail server configured (a real one from my ISP) and mail internal and external works on the command line. In PHP only external users work.
For testing I would like to send to internal users only.
( Ideally I would like to set up lots of aliases that point to one user so mail to:
tom#localhost.com, dick#localhost.com, harry#localhost.com end up in /var/mail/johnsmith )
I'd be greatful if someone could help here. I'm hesitant to edit the postfix config files...
On the command line johnsmith#localhost works but not in PHP. It's using cakePHP and I checked the value of $email-addr just before the send ($this->Email->send();) and the value is johnsmith#localhost. I'm not that familiar with cakePHP yet. The var/log/mail shows nothing, only external email addresses.
(server is Suse linux)
You can use the basic mail php function
http://php.net/manual/en/function.mail.php
Under linux, mail php function relies on sendmail, just check that sendmail is properly installed.
In /etc/postfix/main.cf add localhost.com:
mydestination = $myhostname, localhost.$mydomain,localhost,localhost.com
This allows sending on "localuser#localhost.com" via command line. I loaded up a test php mail form script in a browser and it works, sending mail through to /var/mail/localuser.
At the moment it means I have to check each local users /var/mail file. I'm working on the alias. My first attempt at that failed.
I am trying to send out password reset links for when users forget their password to login to a system I am creating. The problem is, the smtp server is supposedly not configured on the server my system is hosted on. So whenever I try to use the php mail() function to send an email to an internal email address, the emails fail to send, but outside email address (tested with a gmail account), the emails go through. I believe this is because my server is sending directly out to the internet instead of passing through an internal smtp server to resolve where our domain emails should be sent. I was wondering if anyone knew how to configure this on an Xserve or if they knew how to specifically tell the php mail() function where to initially send the email. Any help or pointing in the right direction would be extremely helpful.
Thank you!
mail() doesn't send mail, it just hands things over to the local SMTP server. It does NOT reach out to the recipient's server to deliver the mail. In real world terms, mail() walks your letter down the street and drops it into the neighborhood mailbox. After that, it has absolutely nothing more to do with mail delivery.
Check your local SMTP server's logs to see why the local mails aren't being delivered. There should be a line or two saying why it's registered. Perhaps the local MTA (mail-transfer agent, aka the local "mail man") isn't configured properly.
You can control mail() with it's settings.
This might not solve your overall problem, but hopefully it's useful. This related answer has more information.
We just addressed this problem internally here. Hopefully this will help you as well.
Our environment:
Ubuntu 12.04 LTS
PHP 5.3.10
We could telnet into our SMTP server and send mail from our web server, so it wasn't a permissions issue. When attempting to mail externally, all works perfectly. When attempting to mail internally, silent failure.
Our PHP is using sendmail, which by default, attempts to relay mail to 127.0.0.1. Point this at your SMTP server by editing /etc/mail/sendmail.cf. Update the line from:
# "Smart" relay host (may be null)
DS
to
# "Smart" relay host (may be null)
DSyour.smtp.server.com
Restart sendmail and try sending yourself an email via PHP.
This is something that occurs on Parellels’ PLESK server administration software.
Find your ‘main.cf’ configuration file for PostFix, which for CentOS 6, is located at
/etc/postfix/main.cf
If you can’t find it, do a
which postfix
SSH command to at least see where Postfix is on your server.
Then, open the file up through a text editor, or in the Linux shell, and make these lines (should be at the end of the file, around line 677) :
virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
commented out like this :
#virtual_mailbox_domains = $virtual_mailbox_maps, hash:/var/spool/postfix/plesk/virtual_domains
#virtual_alias_maps = $virtual_maps, hash:/var/spool/postfix/plesk/virtual
#virtual_mailbox_maps = hash:/var/spool/postfix/plesk/vmailbox
Then, restart the Postfix service
sudo service postfix restart
Apache while your at it (can’t hurt), and voila! Your email address should be receiving those emails now. This also doesn’t affect any of your regular emails or anything else, either.
Is there a way that I can configure the WAMP server for PHP to enable the mail() function?
Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I'm sure someone more experienced may be able to help, or they may perhaps agree with me.
If you just want to test, here is a great tool for testing mail locally, that requires almost no configuration:
http://www.toolheap.com/test-mail-server-tool/
Install Fake Sendmail (download sendmail.zip).
Then configure C:\wamp\sendmail\sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user#gmail.com
auth_password=your_password
The above will work against a Gmail account.
And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
Using an open source program call Send Mail, you can send via wamp rather easily actually. I'm still setting it up, but here's a great tutorial by jo jordan. Takes less than 2 mins to setup.
Just tried it and it worked like a charm! Once I uncommented the error log and found out that it was stalling on the pop3 authentication, I just removed that and it sent nicely. Best of luck!
You need a SMTP server to send your mail. If you have one available which does not require SMTP authentification (maybe your ISP's?) just edit the 'SMTP' ([mail function]) setting in your php.ini file.
If this is no option because your SMTP server requires authentification you won't be able to use the internal mail() function and have to use some 3rd party class which supports smtp auth. e.g. http://pear.php.net/package/Mail/
I tried Test Mail Server Tool and while it worked great, you still need to open the email on some client.
I found Papercut:
https://github.com/ChangemakerStudios/Papercut-SMTP
(updated URL for 2021)
For configuration it's easy as Test Mail Server Tool (pratically zero-conf), and it also serves as an email client, with views for the Message (great for HTML emails), Headers, Body (to inspect the HTML) and Raw (full unparsed email).
It also has a Sections view, to split up the different media types found in the email.
It has a super clean and friendly UI, a good log viewer and gives you notifications when you receive an email.
I find it perfect, so I just wanted to give my 2c and maybe help someone.
Sendmail wasn't working for me so I used msmtp 1.6.2 w32 and most just followed the instructions at DeveloperSide. Here is a quick rundown of the setup for posterity:
Enabled IMAP access under your Gmail account (the one msmtp is sending emails from)
Enable access for less secure apps. Log into your google account and go here
Edit php.ini, find and change each setting below to reflect the following:
; These are commented out by prefixing a semicolon
;SMTP = localhost
;smtp_port = 25
; Set these paths to where you put your msmtp files.
; I used backslashes in php.ini and it works fine.
; The example in the devside guide uses forwardslashes.
sendmail_path = "C:\wamp64\msmtp\msmtp.exe -d -C C:\wamp64\msmtp\msmtprc.ini -t --read-envelope-from"
mail.log = "C:\wamp64\msmtp\maillog.txt"
Create and edit the file msmtprc.ini in the same directory as your msmtp.exe file as follows, replacing it with your own email and password:
# Default values for all accounts
defaults
tls_certcheck off
# I used forward slashes here and it works.
logfile C:/wamp64/msmtp/msmtplog.txt
account Gmail
host smtp.gmail.com
port 587
auth on
tls on
from ReplaceWithYourEmail#gmail.com
user ReplaceWithYourEmail#gmail.com
password ReplaceWithYourPassword
account default : gmail
I used Mercury/32 and Pegasus Mail to get the mail() functional. It works great too as a mail server if you want an email address ending with your domain name.