Reputation: 15925
Why isn't the following working?
<?php
mail('[email protected]', 'some text here', 'some text here');
?>
access.log shows:
127.0.0.1 - - [16/Jan/2013:08:46:52 +0000] "GET /test_mail.php HTTP/1.1" 200 294 "-" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11"
error.log shows:
nothing
I have also tried the following from the terminal:
echo 'body' | sendmail [email protected]
and nothing.
and the mail.log shows:
Jan 16 08:57:24 ubuntu postfix/smtp[4081]: connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4001:c02::1a]:25: Network is unreachable
I don't get an email in my inbox or spam box.
Upvotes: 3
Views: 4915
Reputation: 15925
Got it working using the following:
sudo apt-get install sendmail
Edit your php.ini to uncomment sendmail - mine was located in
/etc/php5/apache2/
put
sendmail_path = /usr/sbin/sendmail -t -i
Save changes and restart apache.
Upvotes: 0
Reputation: 51411
postfix/smtp[4081]: connect to alt1.gmail-smtp-in.l.google.com[2a00:1450:4001:c02::1a]:25: Network is unreachable
It looks like you're using Postfix with IPv6 support enabled, but you are not on an IPv6 network that is connected to the internet at large, or have firewall rules preventing the connection.
The most simple troubleshooting method will be to edit main.cf
and change inet_protocols
to ipv4
instead of whatever it's currently set to. Be sure to completely restart the Postfix service after making this change. The linked documentation page will have more information on the implications of having IPv6 support enabled.
If you still can't connect after dropping down to IPv4, look for firewall rules between your system and the internet.
I still want to actively encourage you to not use PHP's mail()
function. mail()
does not guarantee delivery. All it guarantees it that it tried to hand off mail to something behind the scenes. It gives you no clues when things go wrong. Instead, please use a third-party mail library like Swiftmailer or PHPMailer in combination with a known-working SMTP server. These libraries make it far, far more obvious when something goes wrong while sending, and you get tremendously useful features to boot.
Upvotes: 8