DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Php mail error

By: | 24 Jul 2009 11:50 am

this page:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 2</title>

</head>

<body>
<?php mail(`forms@...`, `test subject`, `test message`); ?>
</body>

</html>

generates this:
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:homepagesddtest3.php on line 10
anybody have any suggestions?

Comments

Since you are running this on a Windows computer I need to ask the obvious first, are you running a mail server on your computer?

If not, XAMPP comes with one which allows you to test local mail delivery.
http://www.apachefriends.org/en/xampp-windows.html

Or you could try this function, which allows you to talk to a SMTP
server directly. It does not work with safe_mode on
The $CONF array contains setting values, I think you can guess what is
contains but let me know if you have a question.

function smtp_mail($CONF, $to, $subject, $body, $headers)
//PHP SMTP mail function with custom smtp server support
{
$recipients = rtrim($to, ","); //Remove any trailing comma
$recipients = explode(`,`, $recipients); //Create Array containg recipients

if (!($socket = fsockopen($CONF[`SMTPServer`], $CONF[`SMTPServerPort`]
, $errno, $errstr, 15)))
echo(`Unable to connect to SMTP server `.$CONF[`SMTPServer`].`
(`.$errno.`) (`.$errstr.`)`);

server_parse($socket, `220`);

if ($CONF[`SMTPUser`] != `` && $CONF[`SMTPPassword`] != ``)
{
fwrite($socket, `EHLO `.$CONF[`SMTPServer`]."rn");
server_parse($socket, `250`);

fwrite($socket, `AUTH LOGIN`."rn");
server_parse($socket, `334`);

fwrite($socket, base64_encode($CONF[`SMTPUser`])."rn");
server_parse($socket, `334`);

fwrite($socket, base64_encode($CONF[`SMTPPassword`])."rn");
server_parse($socket, `235`);
}
else
{
fwrite($socket, `HELO `.$CONF[`SMTPServer`]."rn");
server_parse($socket, `250`);
}

fwrite($socket, `MAIL FROM: <`.$CONF[`EmailContact`].`>`."rn");
server_parse($socket, `250`);

$send_to = `To: `; //Start creating the To: Field for SMTP

while (list(, $email) = @each($recipients))
{
fwrite($socket, `RCPT TO: <`.$email.`>`."rn");
server_parse($socket, `250`);

$send_to .= `<`.$email.`>, `;
}

fwrite($socket, `DATA`."rn");
server_parse($socket, `354`);

fwrite($socket, `FROM:
website<`.$CONF[`EmailContact`].`>`."rn".`Subject:
`.$subject."rn".$send_to."rn".$headers."rnrn".$body."rn");

fwrite($socket, `.`."rn");
server_parse($socket, `250`);

fwrite($socket, `QUIT`."rn");
fclose($socket);

return true;
}

By: | 24 Jul 2009

assumption about your operating system. Windows does not typically have a mail server running on it and this message is an indication that PHP can`t talk to a mail server.

Linux (and Unix) systems do come with mail server software most of the time.  The main ones are sendmail, postfix, and exim. You would be far better off setting up a Linux machine for your development. Most affordable web hosting is done on Linux so it pays to have a similar environment for development compared to what will be used in production. These days it is not very difficult to get a Linux server running at home. You can even do it as a virtualized instance or a dual-boot system on the machine where Windows runs.

By: | 24 Jul 2009

this page:
<?php mail(`forms@...`, `test subject`, `test message`); ?>

generates this:

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:homepagesddtest3.php on line 10

anybody have any suggestions?


------------------------------------
Edit php.ini
(On my system => binphpphp5.2.9-1php.ini)

[mail function]
; For Win32 only.
SMTP = mail.somedomain.com
smtp_port = 25
; Use Port 26 if 25 doesn`t work

; For Win32 only.
sendmail_from = someone@...

By: | 24 Jul 2009

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move