2

Hey guys, recently I just installed msmtp in linux and I even send a mail from the terminal and it worked:

echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t username@gmail.com

But in php, after editing the php.ini file to have this:

sendmail_path = '/usr/bin/msmtp -t'

and using this piece of code:

<?php
if ( mail ( 'myemail@gmail.com', 'Test mail from localhost', 'Working Fine.' ) ){
echo 'Mail sent';
}
else{
echo 'Error. Please check error log.';
}

?>

I get the Mail sent message but don't receive a message in my inbox. Not even in the spam folder. Anything wrong I'm doing?

msmtp configuration file:

defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

account default
host smtp.gmail.com
port 587
auth on user myemail@gmail.com
password password
from myemail@gmail.com
logfile /var/log/msmtp.log

2 Answers 2

1

I got the same problem. Your script says the half solution.. Check your apache error logs, not the msmtp ones, if they even exist.. :) My log file said:

"msmtp: /etc/msmtprc: must be owned by you"

Which was correct actually, my msmtp config file at /etc/msmtp was not owned by http.

My php.ini file is like this:

sendmail_path = "/usr/bin/msmtp -C /etc/msmtprc -t"

Hope this helps.

0

Return Values

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

So, basically this means that message was forwarded to mail transfer tool which in your case is /usr/bin/msmtp. Probably there is nothing wrong with your code. I'd say the appropriate place to look is /var/log/mail.err or other mail related logs.

7
  • @AndrejsCainikovs my Mail.err is empty. Feb 15, 2011 at 14:58
  • Perhaps logging is done to a different file. First of all, have you configured msmtp? Conf example: msmtp.sourceforge.net/doc/msmtprc.txt Feb 15, 2011 at 15:03
  • Yup I think so: here is what's inside the file:defaults tls on tls_starttls on tls_trust_file /etc/ssl/certs/ca-certificates.crt account default host smtp.gmail.com port 587 auth on user myemail@gmail.com password *** from myemail@gmail.com logfile /var/log/msmtp.log Feb 15, 2011 at 15:04
  • Ok, then what /var/log/msmtp.log tells you? Have you tried to execute msmtp from command line just to make sure that it actually works? Feb 15, 2011 at 15:11
  • Yes I did from the command line and it worked( even stated that in my question). I'm checking msmtp.log now. Feb 15, 2011 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.