Forum Moderators: coopster

Message Too Old, No Replies

Failed to connect to mailserver using php mail script

please help

         

phpsytesnet

10:20 am on Jan 31, 2005 (gmt 0)



Warning: mail() [function.mail]: Failed to connect to mailserver at "nnn.nnn.nnn.nnn" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\web_root\mail3.php on line 8

_______________________________________________

I able to connect my mail server using outlook .I can receive and send emails using outlook, but when I tried to send an email using php scrpit.I got above error.
I think everything is ok about SMTP AND PORT.
you can see below

<snipped specifics>
________________________________________________

php.ini file config.
[mail function]
; For Win32 only.

SMTP = nnn.nnn.nnn.nnn
smtp_port = 25

; For Win32 only.
sendmail_from = support@example.net
_________________________________________________

I'm using windows local authentication for incoming/outgoing message
OS- windows server 2003,
webserver apache 2.0.52 php 5.0.3
___________________________
here is code

<?php
$to = "Admin <support@example.net>";
$subject = "This is a test email";
$message = "Dear John,\n\nThis is a fake email, I hope you enjoy it.\n\nFrom Jane.";
/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
if (mail($to,$subject,$message, $headers))
{
echo "<h4>Thank you for sending email</h4>";
}

else
{
echo "<h4>Can't send email to $to</h4>";
$error = (isset($php_errormsg))? $php_errormsg : '';
echo $error;
}
?>
_________________________________________________

really I do not understand whats wrong. do I need to change something in my httpd.config

[edited by: coopster at 2:49 am (utc) on Feb. 1, 2005]
[edit reason] generalized ip, url and email [/edit]

jatar_k

8:13 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld phpsytesnet,

are you using an external smtp server or is it located on the same machine?

have you tried using the name instead of the ip for the smtp server?

dogsbarking

11:20 pm on Feb 1, 2005 (gmt 0)

10+ Year Member



I am having the same problem. my external mailserver (ISP) works ok in outlook but my php script returns the
"Warning: mail(): Failed to connect to mailserver" error when i try to send an email.

I have scoured the net looking for an answer or what to test to no avail. I am using apache, php on windows.

Any further ideas would be appreciated.

coopster

12:49 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, dogsbarking.

You may want to have a look at your SMTP settings in your

php.ini
file. Short details can be found in message #2 in the Installing PHP5 Under Windows XP and Apache [webmasterworld.com] thread in the PHP Forum Library [webmasterworld.com].

phpsytesnet, your configuration settings look correct at first glance here. Along with jatar_k's recommendations, since you seem to be running your own SMTP server, have you checked the logs there yet? Is it being blocked because of some spam filtering or otherwise? If not, this may be the old mail() and CRLF vs LF [webmasterworld.com] issue...

dogsbarking

11:10 pm on Feb 2, 2005 (gmt 0)

10+ Year Member



Thanks coopster. I have checked my php.ini settings and they seem correct to me.
--------------------------------------
[mail function]
; For Win32 only.
SMTP = mail.externalmailserver.com
;smtp_port = 25

; For Win32 only.
sendmail_from = myemailaddress
--------------------------------------

Is there anything else i have to do (naturally i replace the relevant mail and from with my actual servers etc).

I am wonder if there is something my ISP has done to not allow me to send email via a php script seeing i can use outlook to send and receive email using the same mail server.

Any ideas.

coopster

1:39 am on Feb 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Quite possible. If they require authentication first, then you may have issues.

cprescott1972

8:32 am on Feb 4, 2005 (gmt 0)

10+ Year Member



Hello! I am having the same problem. I suspect that it is the password validation that is required when I get my email through Outlook. Anyway, is there someway to send a password along with the SMTP request?

I'm just setting up a test server environment on a computer at home to learn a bit of PHP but I can't get past this SMTP error when using the mail() function. So I am not too worried about security since it's just a test environment... I am not sure if this is an issue with trying to auto-validate the SMTP connect. Any more thoughts. Thanks in advance!

jatar_k

6:26 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



one of my isp's requires me to check my email before I can send as a form of authentication. I believe after you check your mailbox it authenticates you for 30 mins or so.

coopster

6:59 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, cprescott1972.

I have often pondered that too, jatar_k. How does it work on my server from home when sending email through my ISP which requires authentication? (I can always fall back on one of the external servers, but typically I just throw the ISP's mail server into the directive and I'm good to go.) However, I have my email client checking the mailbox every 5 minutes too, so there likely is my answer.

cprescott1972

7:18 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



Hello. First of all, I didn't have luck trying to connect after I had logged in to my email. I have contacted my isp who I send mail through and who was the path for my outgoing SMTP mail in the script / php.ini page. They have sent the following response.

"We would like to inform you that the SMTP path being used by you is correct. But in your php mail() function, you have not used the setting for My Server Requires Authentication, which is essential to send email to SBC Server. Hence, please use the appropriate commands/script to provide the said setting in your php mail()function."

So from this it sounds like there is some sort of "My Server Requires Authentication" parameter for the php mail() function. Has anyone heard of this added bit of code instruction? It seems to me that there could be some validation within the code then this would work. It's just whether this is a vaild part of the php language.

I hope this question isn't too naive. I'm just getting started. Thanks!

coopster

7:51 pm on Feb 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are going to have to send your own headers to authenticate. Have a look at fsockopen() [php.net] or you can use the PEAR Mail class.

pkellogg

2:03 am on Mar 6, 2005 (gmt 0)



I had same problem today. SBC requires authentication. This worked for me:

[phpmailer.sourceforge.net...]
---------------------------------------------------
testmail.php (from above site)
--------------------------------------------------
<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.pacbell.yahoo.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "pkellogg@pacbell.net"; // SMTP username
$mail->Password = "secret"; // SMTP password

$mail->From = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("pkellogg@pacbell.net","Patrick Kellogg");
// $mail->AddAddress("ellen@site.com"); // optional name
//$mail->AddReplyTo("info@site.com","Information");

$mail->WordWrap = 50; // set word wrap
// $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
// $mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML

$mail->Subject = "Here is the subject";
$mail->Body = "This is the <b>HTML body</b>";
$mail->AltBody = "This is the text-only body";

if(!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
?>

--------------------------------------------------
pfk

jatar_k

4:59 pm on Mar 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld pkellogg