I'm using the sendmail package and php, When I try to use the mail function in PHP it returns true but nothing is sent.
php config
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path =/usr/sbin/sendmail -t -i
php file
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
trace(mail('jamie#domain.tld','Testing','test.'));
the mailer log is displaying this
mail() on [/var/www/misc/mail.php:5]: To: jamie#domain.tld -- Headers:
Running sendmail through the CLI as this:
echo -e "To: jamie#domain.tld\nSubject: Test\nTest\n" | sendmail -bm -t -v
Returns "Sender ok", "Recipient ok"
Anyone know of anything which could be causing php to not send the email?
PHP has nothing to do with mail delivery. Its job begins and ends with handing the email off to the specified SMTP agent/server. If mail() does not return a boolean FALSE, then PHP's job has succeeded and it's out of the picture.
Check your SMTP server's logs to see what happens to the email after the handoff is completed. It's quite likely the mail is being rejected/greylisted/spamfiltered into oblivion, because PHP's mail() truly blows.
Consider switching to either Swiftmailer or PHPMailer, both of which offer far better diagnostics of the PHP<->SMTP interactions than mail() ever will.
Testing manually from the command line means little: your shell environment is very different from the in-webserver environment that your script is likely executing in - apples and oranges.
This can be misleading. PHP will return true because, as far as its concerned, it has done its part. But it has no guarantee that the SMTP server will honour the request.
When this happened to me once, it turned out my host had implemented a new stipulation that all script mail must feature a 'from' address in the headers, which had to be a valid address associated with the hosting account.
Might be worth investigating that possibility.
Related
Foreword; I've looked through a lot of topics, done what they said, but nothing works for me - so I made this one.
So I'm using xampp/apache to send mail from a php file, but all I get is "Message delivery failed...".
Does anyone know what I'm doing wrong, or maybe how to display an error of whats going wrong because I don't get any errors.
Here is my code..
(I censored my email and pass for obvious reasons)
if (!mail("censored#gmail.com", "title", "blahblahblah", "From: me#hotmail.com")) {
die("<p>Message delivery failed...</p>") . mysqli_error();
}
?>
sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auto = use SSL for port 465, otherwise try to use TLS
auth_username=censored#gmail.com
auth_password=censored
php.ini:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
If any additional information is requested it will be from beyond this point.
Try allowing less secure apps to send you email using this link: https://www.google.com/settings/security/lesssecureapps
SElinux blocks sendmail from web server by default, change settings in SElinux as:
setsebool -P httpd_can_sendmail on
Okay, so I have a simple script that sends an e-mail via PHP's mail function like so:
<?php mail('foo#example.org', 'Subject', 'This is a message', array('From' => 'bar#example.org', 'To' => 'foo#example.org', 'Subject' => 'This is a message')); ?>
It works perfectly when run on a Synology DS212j (a Linux-based NAS using BusyBox for most common shell commands), however as far as I can tell there is no instance of sendmail anywhere that I can find, and the BusyBox sendmail isn't enabled. In fact, if I use ini_get("sendmail_path") then a value of " -t -i" is returned.
There's an environment variable of MAIL=/var/mail/root but this doesn't to do anything either (there is no /var/mail).
So I'm at a complete loss as to how PHP is actually sending its e-mail, so I'm hoping someone might know. I'm having trouble going through sendmail for PHP on another platform (on the same network sigh) so if I can use the same mechanism as my NAS then it could make things easier.
If you have qmail or postfix on your system and they are configured with sendmail wrappers, then PHP can be configured to work with these. Otherwise sendmail binaries must be on the system for php to send email using mail() function.
reference : http://php.net/manual/en/mail.requirements.php
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');
In the php.ini, the sendmail_path is : -femail#site.com -t -i
But, in a subdomain, I need to send email with the sender : email#new.site.com
I tried to use
ini_set('sendmail_path',-femail#new.site.com),
but sendmail_path is system, so nothing append.
I tried to define sender in mail(), doesn't work (on the log of the server, the sender is still email#site.com, but in the email client, the sender is fine, but it doesn't matter).
I tried to define the 5th parameter, but the function just stop working (do nothing, no error).
Any suggestions ?
Thanks,
Greg
Think about how mail is configured in PHP - it's just a wrapper around an exec call (with some predefined arguments). Hence it's trivial to invoke sendmail via exec substituting your own aruments. This is described in the first comment on the page describing PHP mail config. You just need to composite your own headers (sendmail extracts the recipient addresses from the headers to fill in the envelope, any Bcc lines are stripped before the email is forwarded).
Another approach would be to use a SMTP capable abstraction layer such as swiftmailer or phpmailer - but you probably won't be able to use 'localhost' if it's configured as a slave relay.
I've already set sendmail_path to the path of 'sendmail.exe', but PHP didn't send email. it requires mail server or something.
PHP said can't connect to localhost at port 25. The fun fact in the php.ini file is that above the path to 'sendmail.exe', stated "Unix only!????", but 'sendmail.exe' is Windows executable. [i believe the sendmail.exe i have in XAMPP is windows version of the Unix sendmail, so the comment in php.ini might not be at right place]
I'm just only sending email, not receiving email, so why do i need a mail server (like Mercury)? or the SMTP (the protocol) requires a server for both sending & receiving?
As per my thinking, we can just open the port (usually 25? 465?) of the destination server to send message to. Anything wrong in my procedure here and above?
Just can't find the details in similar Stackoverflow questions so i bring up this matter, please help me get enlightened.
Only because you find a file called sendmail.exe on your computer it does not mean that PHP supports that specific binary out of the box.
From sendmail_path:
[...] This directive works also under Windows. If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.
Double check that sendmail.exe on your disk is compatible with PHP.
Try:
sendmail_path = "X:\path\to\sendmail.exe -t"
I'm just only sending email, not receiving email, so why do i need a mail server (like Mercury)? or the SMTP (the protocol) requires a server for both sending & receiving?
You don't need to. It's only likely that the configuration you use with sendmail.exe (that's not the PHP configuration, look for sendmail.ini instead) that you have told sendmail.exe to use an SMTP server.
Either change that, and if sendmail.exe does not provide the feature you're looking for, replace sendmail.exe with something that matches your needs.
It's just that by default it actually makes sense to send emails. So why are you upset about a configuration that makes sense?
See also:
Mock mail on xampp development box