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.
Related
I keep getting this error when I try to send an e-mail in PHP:
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:\wamp\www\dressoholic\register.php on line 50
my php.ini looks like this:
[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 = you#yoursite.com
I'm using my laptop as a server.. What am I doing wrong? Thanks.
You need to be running a mail server locally.
If this is Unix, enable sendmail
If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx
For sending mails using php mail function is used.
But mail function requires SMTP server for sending emails.
we need to mention SMTP host and SMTP port in php.ini file.
Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.
On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!). So, when using PHP under windows, you need to setup a mail server!
Imo the best and most simple tool ist this: http://smtp4dev.codeplex.com/
SMTP4Dev is a simple one-file mail server tool that does collect the mails it send (so it does not really sends mail, it just keeps them for development). Perfect tool.
If you are running your application just on localhost and it is not yet live, I believe it is very difficult to send mail using this.
Once you put your application online, I believe that this problem should be automatically solved. But i think ini_set() helps you to change the values in php.ini during run time.
First of all, you aren't forced to use an SMTP on your localhost, if you change that localhost entry into the DNS name of the MTA from your ISP provider (who will let you relay mail) it will work right away, so no messing about with your own email service. Just try to use your providers SMTP servers, it will work right away.
PHP mail function can send email in 2 scenarios:
a. Try to send email via unix sendmail program
At linux it will exec program "sendmail", put all params to sendmail and that all.
OR
b. Connect to mail server (using smtp protocol and host/port/username/pass from php.ini) and try to send email.
If php unable to connect to email server it will give warning (and you see such workning in your logs)
To solve it, install smtp server on your local machine or use any available server. How to setup / configure smtp you can find on php.net
Change SMTP=localhost to SMTP=smtp.gmail.com
I keep getting this error when I try to send an e-mail in PHP:
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:\wamp\www\dressoholic\register.php on line 50
my php.ini looks like this:
[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 = you#yoursite.com
I'm using my laptop as a server.. What am I doing wrong? Thanks.
You need to be running a mail server locally.
If this is Unix, enable sendmail
If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx
For sending mails using php mail function is used.
But mail function requires SMTP server for sending emails.
we need to mention SMTP host and SMTP port in php.ini file.
Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.
On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!). So, when using PHP under windows, you need to setup a mail server!
Imo the best and most simple tool ist this: http://smtp4dev.codeplex.com/
SMTP4Dev is a simple one-file mail server tool that does collect the mails it send (so it does not really sends mail, it just keeps them for development). Perfect tool.
If you are running your application just on localhost and it is not yet live, I believe it is very difficult to send mail using this.
Once you put your application online, I believe that this problem should be automatically solved. But i think ini_set() helps you to change the values in php.ini during run time.
First of all, you aren't forced to use an SMTP on your localhost, if you change that localhost entry into the DNS name of the MTA from your ISP provider (who will let you relay mail) it will work right away, so no messing about with your own email service. Just try to use your providers SMTP servers, it will work right away.
PHP mail function can send email in 2 scenarios:
a. Try to send email via unix sendmail program
At linux it will exec program "sendmail", put all params to sendmail and that all.
OR
b. Connect to mail server (using smtp protocol and host/port/username/pass from php.ini) and try to send email.
If php unable to connect to email server it will give warning (and you see such workning in your logs)
To solve it, install smtp server on your local machine or use any available server. How to setup / configure smtp you can find on php.net
Change SMTP=localhost to SMTP=smtp.gmail.com
Here's what's in my php.ini file:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
Is it possible to simply change localhost to smtp.live.com and change the port (smtp_port) to point to a different port (specifically, 567, as required by Microsoft) in order to send email to a Microsoft Live email address via PHP? I tried the normal mail() route, but I never received the email from the script, and can only assume it has to do with SMTP authentication. I don't have very much experience with PHP.
No, that won't work. smtp.live.com requires authentication, and the PHP mail() command does not support authentication. As Pascamel suggested, you should use a library that supports sending mail through a remote SMTP server using authentication. phpmailer is very good.
Have a look at PHPMailer : https://github.com/PHPMailer/PHPMailer
I'm using it to send emails through a GMail account, settings are pretty easy!
This way you won't have to update your php.ini
in php.ini you can change smtp server to different server ONLY for WINDOWS machines.
You can't do it for unix machines. it just ignores even if you set smtp = yourserver.
I know that to send e-mail from localhost on Windows, you need to change SMTP server in php.ini however this is valid only on Windows:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
So what I should do to be able send e-mails from Linux OS?
I would suggest installing ssmtp rather than installing a full mail server like postfix. If this is just a local test environment, you probably don't need a full MTA. ssmtp is very easy to setup--you just supply your smtp credentials for a remote server. There's a tutorial here.
This worked for me on Linux Mint 17 for sending emails from the localhost:
sudo apt-get install sendmail
If you're running Debian and variants thereof (*buntu, etc.), you can install a mail server by running sudo tasksel install mail-server, which should set you up with basic email capabilities. You can test this by running in command line echo 'body' | sendmail recipient#example.net, or as others have mentioned, mail($to, $subj, $msg) in PHP.
There should be a stub in your php.ini file already, something like:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = /usr/sbin/sendmail -t -i
Check that the command specified exists on your filesystem and you have (installed and) configured the MTA correctly.
If you've not already got an MTA set up, there are lots of MTAs available for Linux systems, I'd recommend sendmail (comples/difficult to configure but great performance and amazing flexibility) or postfix (easier to configure, good security out of the box).
Learn how to use the 'mail' cli client or run a different MUA on the server to seperate configuring the MTA from PHP integration.
To send mail from localhost (WAMP, XAMP, or LAMP) you can use PHPMailer package (Download PHPMailer from here).
First you have to edit the "php.ini" To find this file display the phpinfo by using following code from the WAMP server. Create one php file and add this content.
<?php
echo phpinfo();
?>
There search for "Loaded Configuration File" That will be the path to your php.ini.
In this file remove the ;(semi colon) given to extension=php_openssl.dll.
After downloading PHPMailerX.X.X package
Extract->Copy the full folder into your project folder.
In test folder there is one file called testemail.php.
Change the parameter as your need. (Example given below).
Then in the browser type 127.0.0.1/PHPMailer/test/testemail.php.
Then it will show successful message if email sent, else it will give error message.
Example:
//add these codes if not written
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465;
//You have to change these parameters to your requirements.
//…….code….
$mail->Username = “abc#gmail.com”; // GMAIL username
$mail->Password = “abcdefgh”; // GMAIL password
//……..code….. There are many other functions to attach file etc.. For that refer doc file.
$mail->AddAddress(“destination#gmail.com”,”Nick name”);
//…….code…..
Setup sendmail or exim. Search in your package manager for either of the option and install them. Senmail is common and setting it up should do the job. The mail command on linux is an MUA or mail user agent, a Mail User Agent (MUA) is an application that is used to send and receive email, more of a client. Whereas mail transfer agent transfers emails from one computer to another using a client–server application architecture.
You need to install a MTA such as sendmail (Some distros like Debian seem to prefer exim, or maybe postfix).
Using PHP's SMTP implementation is a bad idea, because it will not respect the retry requirement of RFC5321 "4.5.4.1. Sending Strategy: mail that
cannot be transmitted immediately MUST be queued and periodically
retried by the sender."
This violation of an RFC "MUST" requirement generally reduces robustness and will interfere with correct interoperation in most cases. This is why you need to use a local MTA (under Linux or Windows). Ideally, you need a non-SMTP mechanism for submitting messages to the MTA, which is why PHP will should execute "sendmail" to send mail. It tends to do this by default if a MTA is installed.
I keep getting this error when I try to send an e-mail in PHP:
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:\wamp\www\dressoholic\register.php on line 50
my php.ini looks like this:
[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 = you#yoursite.com
I'm using my laptop as a server.. What am I doing wrong? Thanks.
You need to be running a mail server locally.
If this is Unix, enable sendmail
If this is Windows install the Simple Mail Transfer Server (not sure if the name is correct) component of IIs. E.g. for windows 2003 follow this: http://msdn.microsoft.com/en-us/library/8b83ac7t.aspx
For sending mails using php mail function is used.
But mail function requires SMTP server for sending emails.
we need to mention SMTP host and SMTP port in php.ini file.
Upon successful configuration of SMTP server mails will be sent successfully sent through php scripts.
On windows, nearly all AMPP (Apache,MySQL,PHP,PHPmyAdmin) packages don't include a mail server (but nearly all naked linuxes do have!). So, when using PHP under windows, you need to setup a mail server!
Imo the best and most simple tool ist this: http://smtp4dev.codeplex.com/
SMTP4Dev is a simple one-file mail server tool that does collect the mails it send (so it does not really sends mail, it just keeps them for development). Perfect tool.
If you are running your application just on localhost and it is not yet live, I believe it is very difficult to send mail using this.
Once you put your application online, I believe that this problem should be automatically solved. But i think ini_set() helps you to change the values in php.ini during run time.
First of all, you aren't forced to use an SMTP on your localhost, if you change that localhost entry into the DNS name of the MTA from your ISP provider (who will let you relay mail) it will work right away, so no messing about with your own email service. Just try to use your providers SMTP servers, it will work right away.
PHP mail function can send email in 2 scenarios:
a. Try to send email via unix sendmail program
At linux it will exec program "sendmail", put all params to sendmail and that all.
OR
b. Connect to mail server (using smtp protocol and host/port/username/pass from php.ini) and try to send email.
If php unable to connect to email server it will give warning (and you see such workning in your logs)
To solve it, install smtp server on your local machine or use any available server. How to setup / configure smtp you can find on php.net
Change SMTP=localhost to SMTP=smtp.gmail.com