php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #15373 mail() not working, no error with invalid SMTP or email address
Submitted: 2002-02-04 21:00 UTC Modified: 2010-06-23 11:28 UTC
Votes:136
Avg. Score:4.2 ± 1.2
Reproduced:100 of 107 (93.5%)
Same Version:29 (29.0%)
Same OS:39 (39.0%)
From: alonso at admintek dot net Assigned:
Status: Not a bug Package: Mail related
PHP Version: 4.2.1 OS: win2000
Private report: No CVE-ID: None
 [2002-02-04 21:00 UTC] alonso at admintek dot net
I moved a program from winnt4 php 4.0.6 to win2000 php 4.1.1 and now mail doesn't work.

In fact no matter what I put in SMTP in php.ini or if the email address is correct, mail() always returns 1. Always, immediately returns 1. It never sends emails even with correct parameters and SMTP.

If it at least gave an error I would know why it doesn't work.

I tried 4.1.0 and is same thing.

OS is win2000 fresh install with IIS5. Webserver is Apache but php.exe works the same way.


Patches

php.ini (last revision 2010-06-16 12:06 UTC by eddykuff at 37 dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-04 21:15 UTC] alonso at loquequeda dot com
I just tried php 4.0.6 in same machine and it now gives errors when incorrect smtp. And guess what: it sends emails too when smtp is correct!

So this is a problem in 4.1.0 and 4.1.0.
 [2002-02-04 21:16 UTC] alonso at loquequeda dot com
I mean 4.10 and 4.1.1
 [2002-02-06 18:54 UTC] mail at egri dot de
Hy,

I have this problem too.
I can receiving email but i can?t sending with smtp.
The smtp server ist correct. I tryed any variations in the
config.php but it still doesn?t work.
My server is a Apache.
I have read in the phpinfo.php on my server that?s the with=smtp registry not exist. So i have downloaded the
Ubeumiau-Php mail-script. It doesn?t work again. It was the same problem.

PLEASE PLEASE HELP ME...

Greetings from Berlin

jam
 [2002-06-02 13:52 UTC] mfischer@php.net
Error reporting has been improved, please try a snapshot from http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-07-02 02:01 UTC] alonso at loquequeda dot com
I have finally tested with php 4.2.1 and php4-win32-latest-zip and both work the same. They do not send the email and always immediately return 1.

Script:
ini_set("SMTP","shouldfail");
echo mail("alonso@xxx.net","test","hola");

returns "1"

Using a correct SMTP also returns "1" and doesn't send the email. I have found no way of sending the email except installing php 4.0.6 which does work.

You said "Error reporting has been improved", how do I use this improved error reporting?
 [2002-07-02 02:06 UTC] alonso at admintek dot net
changed version from 4.1.1 to 4.2.1
 [2002-07-02 03:11 UTC] mfischer@php.net
You don't need to "use" the improved error reporting. It has improvied in that way e.g. when the server returns an error response, you no longer just get "server error" but the message string the server 'said'.

Are you sure you have error_reporting(E_ALL); so you see the warning message if mail should generate one?

The only other way I could remotely see to debug this is that you tell me what your SMTP is and you open it for me to relay so I can do testings (we can do this in private mail of course).
 [2002-07-02 12:39 UTC] alonso at admintek dot net
mfischer, I think you do not understand my situation.
I have in my php.ini:
SMTP = nothing-should-give-error; invalid SMTP
error_reporting	=	E_ALL;
display_errors	=	On	;

Then I have a script with:
//send mail with invalid STMP to invalid address
echo mail("noaddress","test","hola");

It immediately returns "1". Even with invalid SMTP and invalid email it just says "1" no errors are reported.  Then how am I supposed to test my SMTP server if mail() always returns 1 and never sends the email? If I use a correct SMTP and correct address it does the same thing.

I need to make it give some kind of error. Again, if I use php4ts.dll and php4apache.dll from php4.0.6 it says "Bad Message destination" or "Failed to Connect" if I put a valid address and keep the invalid SMTP. With valid address and SMTP the email is sent correctly with 4.0.6.
 [2002-07-02 12:46 UTC] mfischer@php.net
Yup, you were right, I didn't understood your concerns.

Expect it to be fixed soon.
 [2002-09-03 12:23 UTC] 123 at 123 dot com
I ran into this same problem and had to set my smtp Relay Restrictions to allow the program to relay the message through the vertual server.
 [2002-09-21 10:12 UTC] mfischer@php.net
If I run my script through http://snaps.php.net/win32/php4-win32-latest.zip with

---8< php.ini ----
SMTP = 
sendmail_from = whoever
error_reporting = E_ALL
display_errors = On

and

----8< mail_15373.php----
<?php
	echo "Sending mail ...\n";

	$retval = mail("nouser", "subject", "body");

	var_dump($retval);
?>

I get

C:\php>cvsdebug\php -c . mail_15373.php
Sending mail ...

Warning: mail() [http://www.php.net/function.mail]: Failed to connect to mailserver at "" port 25, verify your "SMTP" an
d "smtp_port" setting in php.ini or use ini_set() in mail_15373.php on line 4
bool(false)

Same if I give some nonsense SMTP host:
C:\php>cvsdebug\php -c . mail_15373.php
Sending mail ...

Warning: mail() [http://www.php.net/function.mail]: Failed to connect to mailserver at "acbsdflskadfasklfhas-asdfasdfs"
port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in mail_15373.php on line 4
bool(false)

Please also test http://snaps.php.net/win32/php4-win32-latest.zip
 [2002-10-14 19:26 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2003-03-19 11:03 UTC] lucasnishimura at hotmail dot com
Anyone found a solution to this problem? if so please contact me at the above email address..
thx in advance...
 [2003-11-16 18:59 UTC] doug32x at hotmail dot com
OS       Windows XP home Editio
Server   Apache 1.3.28
PHP      4.3.3

I tried doing this:
<?PHP 
ini_set('smtp_port','25');
mail("doug32x@hotmail.com","Hi","Message")
?> 

I get this: 
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().

I tried by changin the php.ini and it does not work :(

I hope you can help me
Thanks a lot
 [2003-12-19 12:31 UTC] georgealbert2001 at yahoo dot com
i have win98 and iam using devshed ,and i download easy SMTP
to make my PC an SMTP server
i always try to send mail but i fail
could someone tell me how to cofig to send the email
 [2005-10-01 16:26 UTC] morebiz at gmail dot com
Hi, 
I have problem like this too.
I try to change to windows 2003 server with php and it work. After I install antivirus program, can not send mail.
So I just know the reason is Antivirus program !!!.
Now i new install Wins XP Apache+Php and config my antivirus program It Work !!.
Please check your anivirus program.
Good luck.

Greeting from webmaster Thailand.
 [2006-07-21 12:44 UTC] ishongwe at yahoo dot com
Is it possible to use the mail() function without any network connection on windows xp, and if possible how do you do it on the php.ini? 
Remember: Everything seem to be working fine except the mail() function, yet.

Thanks in advance
 [2006-10-05 05:15 UTC] bigredraddish at hotmail dot com
XP PRO SP2
PHP 5.1.6

This is the 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 D:\www\htdocs\sendmail.php on line 43


this is line 43 of my php mail script 

mail("address@dodo.com.au", $subject, $message, $from);

This is my PHP.INI

[mail function]
; For Win32 only.
SMTP = smtp.dodo.com.au


; For Win32 only.
sendmail_from = comment@mywebsite.com
 [2007-07-08 16:50 UTC] kivin_kong at hotmail dot com
i have windows server 2003 R2 with IIS and php 5.2.3 and the mail() function ain't working the i use my ISP DNS server and not workin don't know what to do can someone help it is a recruitment form trying to send it to my email kivin_kong@hotmail.com
 [2007-09-17 18:06 UTC] johan dot jv at gmail dot com
Hello guys, I see that you are having a lot of problem in sending email and some of you might not even been receiving any emails.  Couple of things that you might need to check before sending any emails.
1- Anti-virus (make sure that the antivirus is not blocking port 25)
2- Your firewall, make sure that your fire wall are not blocking port 25, also make sure that you have your SMTP anable to receive email, you can set that up in your Firewall - Start - Settings- Network Connections - Advanced tab - Setting - exceptions "if you SMTP is not there, click Add Port , on the name field you can write (SMTP TCP) and under port type 25, then hit ok. do that again but with the same port and name but with UDP.
3 - REALLY IMPORTANT. if you are behind a router , you ISP might blocked  25 or you might just need to forward port 25 from your router seetings "portforward dot com/"
4- If you want to know if your port 25 is open or available go to this website canyouseeme dot org and on the field type 25 that will tell you if your port is active.

-------
Something else you might try.
-==if you don't know if your SMTP is working or install, Click Start - Setting - Control panel - add & Remove program - on the left side click Add / Remove Window Components - under the Windows Components Wizard you can see Internet Information Services (IIS) Click that and then Click DETAIL (it's on the right side) after that you can see a list of the IIS Server, Click or Check the SMTP Server  __""""Window might ask you for Window XP or your OS CD to install does files"""" make sure you have that on hand if you want to do this step. Then say okay.  Restart your Apache server or you IIS server if you have one, then try to send your email again..... It might work.....doesn't hurt to try. :) Good Luck
 [2007-10-25 11:13 UTC] vvel3000 at yahoo dot co dot in
Warning: mail() [function.mail]: Failed to connect to mailserver at "mail.yourisp.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\1.php on line 7
There was an error


why so you error
 [2008-07-10 15:47 UTC] phpseven at yahoo dot com
smtp server can't run. i tried my best to solve it but it can't send the mail.
 [2008-11-25 17:17 UTC] jeff at jouster dot org
I have this same problem.

I have Windows Server 2003 SP2 IIS 6. PHP6-dev (also same problem with 5.4)

Port 25 is open and I can telnet to the server from my home machine completely outside the network and manually send an email. So I know that SMTP is not the problem and relaying is not a problem.

Here's my script:

<?php
  $success = mail("my@address.tld", "subject", "body", "From: My Name <my@address.tld>");
echo ($success);
if ($success)
{
echo (" success!");
}
else
{
echo (" problem...");
}
?>

When I run this test script I see:

1 success!

However I never get an email. I have php.ini set to log errors (have also tried display errors) and there is never any errors logged or displayed.

php.ini SMTP section:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = my@address.tld

phpinfo() shows all of this information properly (only after I moved the .ini file into the PHP install directory.

I have PHPRC environment variable set to PHP install directory and have added same directory to my PATH env var.

Mail was successfully being sent until another issue caused me to uninstall and reinstall the SMTP Service portion of IIS.

I see no solutions or cause to this problem in this thread. Any new news? Original issue was posted 6 years ago... I can't believe this is still cropping up for people.
 [2009-03-19 00:47 UTC] rmsadik dot ece at gmail dot com
i have problem sending email using mail(). it was working couple of weeks before but now on its not working ...i dont know whats the problem and here is the code

if ($db_result) {
	
	echo "Successful";
		$to = $email;
		$from = "msathh@gmail.com";
		$subject = "Password Request From";
		$message = "PLEASE DO NOT REPLY TO THIS EMAIL\n\n";
		$message .= "unless others can read your email.\n\n\n";
		$message .= "Password: ".$password;
		$headers = "From: ".$from;
		// Set the name of the server for mail processing. This should be handled at the server level but the following
		// statement allows dynamic setting of the SMPT server for testing purposes.
		ini_set("SMTP","mail.sunet.com.au");
		// Attempt to send the mail message.
		//$db_result = mail($to,$subject,$message,$headers);
		
		mail($to,$subject,$message,$headers);
	}
 [2009-03-27 11:37 UTC] real_ganesh at yahoo dot co dot in
Am php to send E-mail,but will be Error.
Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in

-----code----
Contact.html
-----------
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;>charset=iso-8859-1" />
	<title>Cultuzz Digital Media GmbH - Contact</title>
</head>
<center>
	
	<body bgcolor="FF9900">
		<div class="componentheading"><h1>Contact Us</h1></div>
			
		<table width="50%" cellpadding="0" cellspacing="0" border="0" class="contentpane">
	
		<!-- <form action="../Contactus/Contact1.php" method="post"> -->

		<form action="../Contactus/Mailto.php" method="post">

		 <table>
		 <!--  <body background="FF9900"> -->
		  <tr>
			   <td align="right" class="w"><b>Enter your To Address:</b></font></h3></td>
		 	   <td><input type="text" name="toAddr" size="25"></td> 
		  </tr>

		  <tr>
			   <td align="right" class="w"><b>E-mail your From Address:</b></font></td>
			   <td><input type="text" name="fromAddr" size="25"></td>
		  </tr>

		  <tr>
			   <td align="right" class="w"><b>Enter your Password:</b></font></td>
			   <td><input type="password" name="toPass" size="25"></td> 
		  </tr>

		  <tr>
		   <td align="right" class="w"><b>Enter your Subject:</b></font></td>
			<td>
				<input type = "text" name="subject" size="25">
			</td> 
		  </tr>

		   <tr>
		   <td align="right" class="w"><b>Enter your Content:</b></font></td>
			<td>
				<textarea name="content" size="20" cols="25" rows="7"></textarea>
			</td>
	
			</tr>


		  <tr>
		  	<td>
				<center>
					<input type="submit" name="submit" value="Submit">
				</center>
				</td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
				&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
			</tr>
		  </body>
		 </table>
		</form>
	  </body>
	</center>
</html>


<!-- <textarea name="content" size="20" cols="25" rows="7" value="<?php echo $_POST['content']; ?>"></textarea> -->

---------------------
mailto.php
----------------------
<!-- Mail to multiple recipients 
 --> 
 

<?php
   /*$headers = "From:sender@java2s.com\r\n";
   $recipients = "test@java.com,a@java2s.com";
   mail($recipients, "This is the subject","This is the mail body", $headers);
   */
		
		/* $SMTP = 10.200.10.7
		$smtp_port = 25*/
	 
		$toAddr = "toAddr";
        $fromAddr = "fromAddr";
        $toPass = "toPass";
		$subject = "subject";
		$content = "content";
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'From: sk.ganehan@yahoo.co.in\r\n' .
                    'Reply-To: real_ganesh@yahoo.co.in\r\n';
       //u can add
        //$headers .= 'CC : test@test.com\r\n';  
        //$headers .= 'BCC : test@test.com\r\n'; 
   
        mail($toAddr, $fromAddr, $toPass, $subject,$content);
		
		echo "This is To---------------->: $toAddr <br/>";
		echo "This is From----------->: $fromAddr <br/></n>";
		echo "This is Password----------->: $toPass <br/>";
		echo "This is Subject----------->: $subject <br/></n>";
		echo "This is Content----------->: $content <br/></n>";
		echo "This is Headers----------->: $headers <br/></n>";
    
?>
 [2009-06-18 16:33 UTC] omgmain at gmail dot com
Hi,
I am also having the same problem with this. I am using Mac OS X, and it doesn't seem to be sending.
Script:
<?php 
if(!mail($_POST['email'],"blabla","$text_body")){
    echo("Unable to send verification email.");
}else{
    echo("Sent verification email.");
}
?>
Mail seems to always return true.
 [2009-07-07 06:28 UTC] lakshmi at nace dot co dot in
OS       Windows XP home Edition, Redhat Linux 5
Server   Apache 2.2.11
PHP      5.2.9-2

<?php

$Name = "sam"; //senders name
$email = "am@example.com"; //senders e-mail adress
$recipient = "am1@example.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

if(mail($recipient, $subject, $mail_body, $header)) //mail command :)
echo "mail sent";
else
echo "mail not sent";
?>

I get this:

Warning: mail(): Failed to connect to mailserver at "localhost" port 25,
verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set().

I tried by changing the php.ini and it does not work.

I hope you can help me

Request: This is the third time I am posting this query to PHP Bugs, But Still I haven't get any Proper Solutions.

Thanks a lot
 [2009-08-25 01:13 UTC] dallas_thompson2001 at yahoo dot com
i am having a problem like this and am so lost, i cant send mail from 
the server but it wont let mail be sent from the website and they tell 
me it is a problem with the PHP can some look and tell me what i have 
dont wrong and how to make it work.

<?php


//--------------------------------------------------------------------
User Area

$ToEmail = "mail.thirdstreetdesignstudio.com";
$ToName = "Dallas Thompson";
$ToSubject = "Thanks for your email. One of our consultants will 
respond to your request shortly.?";

//--------------------------------------------------------------------





//--------------------------------------------------------------------
Prohibited Area No Changes 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$_POST['_namex'].' <'.$_POST['_emailx'].'>' . 
"\r\n";

$Message = "Sender Name:".$_POST['_namex']."<br/><br/>Sender 
Email:".$_POST['_emailx']."<br/><br/>Sender 
Phone:".$_POST['_phonex']."<br/><br/>Message:".$_POST['_commx'];

if($_REQUEST['_emailx']!=""){
	mail($ToName." <".$ToEmail.">",$ToSubject, $Message, 
$headers);
}


echo "_root.Status=success";


?>
 [2009-09-09 12:13 UTC] ilmi_bunjaku at yahoo dot com
I have e problem, I can not sent email with PHP
the server is wampserver, OS windows xp 
I have one error as you can see:

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 D:\Webroot\PHP\dergo email.php on line 16


the cod which I write is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1" />
<title>Dergo email</title>

</head>

<body>
<?php
$to = "email@yahoo.com";
$subject = "Test mail";
$message = "hello! .";
$from = "email@hotmail.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail sent.";
?>
</body>
</html>

best regards,
ILA
 [2009-09-09 12:15 UTC] pajoye@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 [2010-06-23 08:46 UTC] vengat dot zen at gmail dot com
hi 

check your send mail path (uncomment)
for ini settings.......(after change restart your sever)
 [2010-06-23 11:28 UTC] mfischer@php.net
-Assigned To: mfischer +Assigned To:
 [2010-06-23 11:28 UTC] mfischer@php.net
De-assigning
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 00:01:28 2024 UTC