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');
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 get the following error when my Drupal site tries to send out a welcome email when users are signed up: Failed to connect to mailserver at "secure.emailsrvr.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
I at first set the following in PHP.ini:
SMTP = secure.emailsrvr.com
SMTP_PORT = 465
sendmail_from = support#managerspitstop.com
username = support#managerspitstop.com
password = ****
But I still got the error above so I added the following into the mail.inc file which is a file within the Drupal site:
ini_set("SMTP","secure.emailsrvr.com");
ini_set("smtp_port","465");
ini_set("username", "support#managerspitstop.com");
ini_set("password", "*****");
ini_set("sendmail_from", "support#managerspitstop.com");
But still get the same error. So I contacted Rackspace who I have set up the email with and they have told me the settings I am using are correct. To test this I added the email to Outlook 2013 send out and email and received an email just fine.
I have looked around and couldn't find a solution. Any help will be greatly appreciated.
Please note that this is just a hint for better investigation means, not an answer.
It would be beneficial to make a packet-level inspection of what exactly is going on at the time, when you try to send e-mail out.
For this, install tcpdump:
apt-get install tcpdump
and start a packet capture (run as root):
tcpdump -i any -s 0 -w /tmp/sniff-465.pcap port 465
Perform steps necessary to attempt the e-mail submission to the SMTP server, wait for the response and stop the packet capture by pressing CTRL+C. The resulting file (/tmp/sniff-465.pcap) can be analysed (using wireshark, i.e.) for exact behavior of the attempted SMTP transaction.
BLOODY DRUPAL! Managed to get it working. Turns out my email settings were correct the whole time.
I fixed it by downloading Drupals SMTP module which I placed in httpdocs/sites/all/modules/smtp and then I downloaded phpmailer version 2.2.1 (only required if you are running Drupal 6.x and do not use a version of PHPMailer any higher than 2.2.1 as it will not work) https://github.com/PHPMailer/PHPMailer/releases/tag/v2.2.1 I placed this at httpdocs/sites/all/modules/smtp/phpmailer.
Once that was sorted I went into the Administration section of my Drupal site and went to the modules section and typed in the email settings and BAM it worked :D.
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.
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.
Is the -f additional parameter correctly set in this mail function.
#mail("example#exmaple.com.uy",$title,$body,$headers,"-f");
I am Getting the X Warning from some servers.
Sorry for the basic question but some parts of the documentation got me confused (specially some user comments).
Thanks in advance!
From the manual:
The additional_parameters parameter
can be used to pass additional flags
as command line options to the program
configured to be used when sending
mail, as defined by the sendmail_path
configuration setting. For example,
this can be used to set the envelope
sender address when using sendmail
with the -f sendmail option.
The user that the webserver runs as
should be added as a trusted user to
the sendmail configuration to prevent
a 'X-Warning' header from being added
to the message when the envelope
sender (-f) is set using this method.
For sendmail users, this file is
/etc/mail/trusted-users.
source: http://www.astahost.com/info.php/Sending-Mail-Php39s-Mail-Function_t2728.html
The additional_parameters parameter
can be used to pass an additional
parameter to the program configured to
use when sending mail using the
sendmail_path configuration setting.
For example, this can be used to set
the envelope sender address when using
sendmail with the -f sendmail option.
You may need to add the user that your
web server runs as to your sendmail
configuration to prevent a 'X-Warning'
header from being added to the message
when you set the envelope sender using
this method. Example 3. Sending mail
with extra headers and setting an
additional command line parameter.
i.e:
<?php
mail("nobody#example.com", "the subject", $message,
"From: webmaster#{$_SERVER['SERVER_NAME']}", "-fwebmaster#{$_SERVER['SERVER_NAME']}");
?>
After -f you need to set the outgoing email address to prevent the warning (in this case its webmaster#-the domain-
If your machine runs on a linux server. Your apache install more than likely runs under the user 'www-data'.
you can figure this out easily by going to /etc/apache2 and typing
cat envvars | grep APACHE_RUN_USER
whatever is after '=' is what user apache is running as.
You need to add this user to the trusted-users file. This file is located at /etc/mail/trusted-users
just
nano /etc/mail/trusted-users
and write 'www-data'.
save and you should be good to go.
-f should be followed by the address you want as envelope address on your mail.
#mail("example#exmaple.com.uy",$title,$body,$headers,"-fexample#exmaple.com.uy");
Have you tried sending it without the -f flag?
The user that the webserver runs as
should be added as a trusted user to
the sendmail configuration to prevent
a 'X-Warning' header from being added
to the message when the envelope
sender (-f) is set using this method.
For sendmail users, this file is
/etc/mail/trusted-users.
You need to specify an email address after the -f flag. Like this: "-fexample#example.com". You may also need to add the user that your web server run as to your sendmail configuration.