So this topic does touch both programming + server world, makes more sense to post it here than serverfault.com..
My postfix server is set up to handle mail differently for each domain on the server, however each domain uses the same IP. So, when mail goes out, postfix is unable to track rev IP correctly to determine the correct domain / transport route.
So next option: some how having PHP include a header or smtp setting to say that this mail is coming from "domain.tld"; and postfix determining the route based on that.
So far, I haven't been able to figure it out yet, some fresh brains on this question would be nice.
Take a look at php.ini file /etc/php5/apache2/php.ini on debian:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me#example.com
Uncomment sendmail_from: and set it to your needs.
Make sure you do:
service apache2 restart
or
service httpd restart
to change take effect.
Hope it helps,
Mirko
Related
The following settings within /etc/php/7.0/apache2/php.ini for mail are marked for Win32 only, but setting them appears to work fine on Ubuntu 16.04 / Apache 2.4.18:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.mymailhost.org
; http://php.net/smtp-port
smtp_port = 25
My system mail (sendmail) log also confirms that mail is able to be sent successfully. Can someone explain why these settings are allowed to be used on Linux hosts? Should I be setting them elsewhere?
So, I have read that these settings are forwarded to sendmail, and the details of relaying the mail to the the SMTP host are handled there. So these settings don't seemed to be ignored on Linux systems, just handed off elsewhere to be dealt with.
I have a load balancer that also works as a mail server.
I want the clusters to use the load balancers mail server as their default mail system for the PHP mail() function
Clusters Settings
PHP
The settings on the php.ini file look like this:
[mail function]
SMTP = mail.email.info
smtp_port = 25
sendmail_from = me#example.com
sendmail_path = /usr/sbin/sendmail -t -i
Load Balancer Settings
Postfix
I have added this to the main.cf:
myhostname = mail.email.info
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.1.71 192.168.0.*
as the clusters are on the 192.168.0.* subnet.
The mail server on the LB is working perfectly. I am using it for lots of virtual hosts and it is set up on lots of mail software (for example sparrow) So this is not likely to be an issue with it, but more likely to be to do with the permissions of it.
When running the PHP script on the cluster:
<?php
mail("test#example.com","subject","msg");
?>
Nothing is happening. Why?!
Please do not be afraid to ask for more info.
According to the PHP documentation, the smtp_port and other options are only used on Windows. Generally, PHP's mail() is not really made for using a remote MTA.
I would recommend using a third party library such as SwiftMailer. Not only can you dispatch your mail to a remote MTA, but you get some valuable extras, too:
RFC-compliant mails,
attachments and multipart mails,
S/MIME support for signing and encrypting e-mails,
intuitive object-oriented APIs,
and many more.
I need some help. I am trying to send an email from a php script. My environment comprises of the following:
Operating System: Windows 8
XAMPP version: 1.8.2
php version: 5.4.19
I have the following php script:
<?php
mail('sugar.donkey#gmail.com','Helo','This is a test','From:salt#goodness.com');
?>
The following configuration on send mail configuration file:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=465
auth_username=sugar.donkey+gmail.com
auth_password=[MYPASSWORDHERE]
The configurations on php.ini:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
; SMTP = smtp.gmail.com
; smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster#localhost
I dont get error when I run the php script, but I also dont seem to receive an email. Where am I going wrong ?
I am not sure what os you are running on your webserver, however;
Most Linux installations have sendmail preinstalled, there is always a hassle of setting up SPF/PTR records, to ensure that the email sent by your PHP script is not flagged as spam. A SMTP client called MSMTP can be used to send emails using third-party SMTP servers, this can also be used by PHP's mail() in the place of sendmail.
I hope this helps
https://www.digitalocean.com/community/articles/how-to-use-gmail-or-yahoo-with-php-mail-function
Also for localhost testing, check this out.
http://blogs.bigfish.tv/adam/2009/12/03/setup-a-testing-mail-server-using-php-on-mac-os-x/
Even I am trying to get this configuration work :)
in your case i believe you need to comment out in php.ini
the configuration should be
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = smtp.gmail.com
smtp_port = 465
; For Win32 only.
http://php.net/sendmail-from
sendmail_from = postmaster#localhost
Thank you
I'm learning PHP and have installed XAMPP on my computer.
But I have a problem with the setup as the email option doesn't seem to be working.
After doing some reading I think it has something to do with the below, found on my server in the php.ini file
[mail function]
; For Win32 only.
; *hp://*php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster#localhost
Is there anything I need to change? I have seen software such as swiftmailer mentioned but I don't know if XAMPP has this included already?
My favorite smtp server is hMailServer.
It has a nice windows friendly installer and wizard. Hands down the easiest mail server I've ever setup.
It can proxy through your gmail/yahoo/etc account or send email directly.
Once it is installed, email in xampp just works with no config changes.
XAMPP should have come with a "fake" sendmail program. In that case, you can use sendmail as well:
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP = localhost
; http://php.net/smtp-port
;smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me#example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:/xampp/sendmail/sendmail.exe -t -i"
Sendmail should have a sendmail.ini with it; it should be configured as so:
# Example for a user configuration file
# Set default values for all following accounts.
defaults
logfile "C:\xampp\sendmail\sendmail.log"
# Mercury
#account Mercury
#host localhost
#from postmaster#localhost
#auth off
# A freemail service example
account ACCOUNTNAME_HERE
tls on
tls_certcheck off
host smtp.gmail.com
from EMAIL_HERE
auth on
user EMAIL_HERE
password PASSWORD_HERE
# Set a default account
account default : ACCOUNTNAME_HERE
Of course, replace ACCOUNTNAME_HERE with an arbitrary account name, replace EMAIL_HERE with a valid email (such as a Gmail or Hotmail), and replace PASSWORD_HERE with the password to your email. Now, you should be able to send mail. Remember to restart Apache (from the control panel or the batch files) to allow the changes to PHP to work.
Unless you have a mail server set up on your local computer, setting SMTP = localhost won't have any effect.
In days gone by (long ago), it was sufficient to set the value of SMTP to the address of your ISP's SMTP server. This now rarely works because most ISPs insist on authentication with a username and password. However, the PHP mail() function doesn't support SMTP authentication. It's designed to work directly with the mail transport agent of the local server.
You either need to set up a local mail server or to use a PHP classs that supports SMTP authentication, such as Zend_Mail or PHPMailer. The simplest solution, however, is to upload your mail processing script to your remote server.
I have encountered an error:
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\works\test\registration-code3.php on line 56
Here is my php.ini:
define_syslog_variables = Off
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
How can I fix this?
Based on what you've shown us, particularly this bit:
C:\works\test\registration-code3.php
Leads me to believe your testing some script on your local system. If this is so and you haven't installed and set up a mail server, then of course its not going to work. You require a MTA to actually send the email, PHP just hands off to it.
If you've simply installed XAMPP then you don't have a working MTA to send through without some real work ahead of you.
If you must send email from your dev machine in this fashion, I recommend picking and using a script like Swiftmailer which will allow you to easily use a mail server hosted elsewhere - like your ISP or even google.
It looks like your Windows machine don't have SMTP server on the port 25. I am guessing that it is your development machine. Instead editing your ini file you can try some other SMTP servers, for instance, the one your ISP provided you with.
Try to add the following code to the top of email script:
ini_set("SMTP","mail.domain.com");
ini_set("smtp_port","25");
ini_set('sendmail_from', 'Email#domain.com');