I want to send email from my PHP code, but I received warning messages. So what are the php.ini parameters to set ?
-
1What do the warning messages say? – Sverri M. Olsen Mar 14 '13 at 06:49
-
Go through http://php.net/manual/en/function.mail.php – Engineer Mar 14 '13 at 06:53
-
the warning is : `[14-Mar-2013 09:52:42] 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\MP_Local\lib\mail.lib.php on line 99` – pheromix Mar 14 '13 at 06:54
-
Is the SMTP server even running on `localhost` and port `25` – Bart Mar 14 '13 at 06:55
-
seems your mail function is not succesfully configured... – Jhonathan H. Mar 14 '13 at 07:00
1 Answers
To check/change your PHP mail configuration:
Open your php.ini file (if you don't know where this is, see below) Search for the line that reads [mail function] Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP. Save/close the php.ini file Restart your web server
An example of what the mail settings could look like when you first open the php.ini file:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = me@example.com
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
Additional info is in echoing phpinfo()
you can view your PHP configuration details. You can do this by creating a .php file with the following line on it: <?php phpinfo(); ?>
. When you run this in your browser, you will see a full list of PHP configuration variables. Simply search for the lines that contain php.ini and sendmail_path
to see the values you need to use.
Another idea is you might use ini_set()
to properly config your mail setting like this
Add the following code to the top of your email script if your mail script continues to fail.
// Please specify your Mail Server - Example: mail.example.com.
ini_set("SMTP","mail.example.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'example@YourDomain.com');

- 2,734
- 1
- 19
- 28
-
1Well actually this issue is that WINDOWS does not come with a mail server. You have to install one to make send() work as well as change some config parameters. – RiggsFolly Apr 29 '13 at 22:35