Web Hosting Talk







View Full Version : PHP mail() not working on Windows Server 2003


Infelicitous
08-06-2010, 08:46 AM
Hi,

I'm trying to set up a page that emails the contents of a form to a specified email address. I had this working fine on a Linux server but the site has now been transferred to a server running Windows Server 2003 (don't ask why, it just has!! :rolleyes:), and now the script to send the mail doesn't work anymore. Here is my script:

<?ob_start();?>
<?php
ini_set("SMTP","mydomain.co.uk");
ini_set("smtp_port","25");
ini_set("sendmail_from","email@mydomain.co.uk");

$name = $_POST['name'];
$businessname = $_POST['businessname'];
$type = $_POST['type'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$message = $_POST['message'];

$subject = "You have received a message from: ".$name."";
$message = stripcslashes($message);
$emailcontent = "<img src=\"innologo5.png\" style=\"float:right;\"/><font face=\"verdana, arial, sans serif\">
<h3>You have received a message from:</h3><p />
<b>Name:</b>&nbsp;".$name."<p />
<b>".$name." is enquiring as a:</b>&nbsp;".$type."<p />";
if (isset($_POST['businessname'])){
$emailcontent .="<b>".$name."'s company:</b>&nbsp;".$businessname."<p />";
}
$emailcontent .="<b>".$name."'s contact number:</b>&nbsp;".$tel."<p />
<b>".$name."'s email address:</b>&nbsp;".$email."<p />
<b>".$name."'s message:</b><p />
".$message."</font>";

$from = "From: My name\r\n";
$from .= "Reply-To: ".$email."\r\n";
$from .= 'MIME-Version: 1.0' . "\r\n";
$from .= 'Content-type: text/html; charset=utf-8' . "\r\n";

$address = "email@domain.co.uk";

mail($address, $subject, $emailcontent, $from);

if (!mail($address, $subject, $emailcontent, $from)) {
echo "problem";
exit;
}

exit;
?>
<?ob_flush();?>

There's nothing wrong with the POST data from the form because if I just echo the $_POST variables they work fine :), so I know for sure that it's the mail() function that is the problem. Please help!!

CyberHostPro
08-07-2010, 06:09 PM
Hi

is it shared hosting?? if so its possible PHPMail is disabled. Try using SMTP in your script with SMTP authentication.

PremiumHost
08-07-2010, 11:20 PM
On windows server, php scripts usually use phpmailer class to send email.
Just do a google search you will find plenty of tutorial to update your code.

centauricw
08-09-2010, 04:21 AM
For PHP on Windows, you have to relay through a SMTP server because the default method of calling Sendmail doesn't work (Sendmail being a Unix program). Usually, the IIS SMTP Server is used if you don't have access to a real mail server. You need to set the SMTP server address in the php.ini file and be sure that SMTP support is enabled in PHP.

HostingASPNet
08-15-2010, 06:42 AM
Hello,

You should also check if the mydomain.co.uk allows port 25 connections. If not allow it from the firewall settings.

Regards

kpmedia
08-15-2010, 10:09 PM
Yes, set up the SMTP.
There are some other workarounds, I've done it for vBulletin, but this is easier.