Discussion:
windows mail problem
Andy Tawse
2004-05-24 09:13:54 UTC
Permalink
Hi there,

I've been having difficulty sending emails from Windows machines. I've
seen this problem in a few places before but I can't seem to fix it on
my machine. When I try to use mail() I get :

mail(): "sendmail_from" not set in php.ini or custom "From:" header missing

The code I'm using is :

$headers = "From: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: My Application";

$ok = @mail($friendMail, $CHALLENGE_MAIL_SUBJECT, $mailText, $headers);

This has worked on my linux server before. It is saying I haven't set a
From header but as you can see I have and my php.ini looks like this :

[mail function]
; For Win32 only.
SMTP = localhost
sendmail_from = ***@email.com

The mail server is running and should be accepting connections. I've
tried the IIS SMTP server and also Argosoft, set both of them to accept
connections but it doesn't seem to get as far as the SMTP server.

I've tried it on my local machine (XP Pro, IIS 5, PHP 4.3.6) and on the
production server (Win 2003, IIS 6, PHP 4.3.6). I've restarted and done
all the things I've found suggested for this problem but no joy.

Can anyone help?

Thanks for your time,

Andy Tawse.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
David Felton
2004-05-24 12:10:02 UTC
Permalink
The Win32 implementation of mail() is notoriously flaky. the approach I take
is to write the raw email directly out to the pickup folder in mailroot. A
function along these lines should help you out:

function sendMail($mailto, $mailfrom, $subject, $text, $format)
{
$maildrop="c:\\inetpub\\mailroot\\pickup\\";//change this to the
location of your mailroot

$filename=<work out some random filename here>;
$fp=fopen($maildrop.$filename, "w");

//different headers for different mail types
if($format=="plain")
fwrite($fp,"Content-Type: text/plain\r\nFrom:
$mailfrom\r\n");
else if($format=="html")
fwrite($fp,"Content-Type: text/html;
charset=iso-8859-1\r\nFrom: $mailfrom\r\n");

//write the email out to the file
fwrite($fp,"To: <$mailto>\r\n");
fwrite($fp,"Subject: $subject\r\n");
fwrite($fp,"\r\n");
fwrite($fp,"$text\r\n\r\n");
fclose($fp);
}

hope that helps.

-----Original Message-----
From: Andy Tawse [mailto:***@newmediacollective.com]
Sent: 24 May 2004 10:14
To: php-***@lists.php.net
Subject: [PHP-WIN] windows mail problem


Hi there,

I've been having difficulty sending emails from Windows machines. I've
seen this problem in a few places before but I can't seem to fix it on
my machine. When I try to use mail() I get :

mail(): "sendmail_from" not set in php.ini or custom "From:" header missing

The code I'm using is :

$headers = "From: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: My Application";

$ok = @mail($friendMail, $CHALLENGE_MAIL_SUBJECT, $mailText,
$headers);

This has worked on my linux server before. It is saying I haven't set a
From header but as you can see I have and my php.ini looks like this :

[mail function]
; For Win32 only.
SMTP = localhost
sendmail_from = ***@email.com

The mail server is running and should be accepting connections. I've
tried the IIS SMTP server and also Argosoft, set both of them to accept
connections but it doesn't seem to get as far as the SMTP server.

I've tried it on my local machine (XP Pro, IIS 5, PHP 4.3.6) and on the
production server (Win 2003, IIS 6, PHP 4.3.6). I've restarted and done
all the things I've found suggested for this problem but no joy.

Can anyone help?

Thanks for your time,

Andy Tawse.
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
**********************************************************************
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Andy Tawse
2004-05-24 14:05:37 UTC
Permalink
That works great, thanks a lot.
Post by David Felton
The Win32 implementation of mail() is notoriously flaky. the approach I take
is to write the raw email directly out to the pickup folder in mailroot. A
function sendMail($mailto, $mailfrom, $subject, $text, $format)
{
$maildrop="c:\\inetpub\\mailroot\\pickup\\";//change this to the
location of your mailroot
$filename=<work out some random filename here>;
$fp=fopen($maildrop.$filename, "w");
//different headers for different mail types
if($format=="plain")
$mailfrom\r\n");
else if($format=="html")
fwrite($fp,"Content-Type: text/html;
charset=iso-8859-1\r\nFrom: $mailfrom\r\n");
//write the email out to the file
fwrite($fp,"To: <$mailto>\r\n");
fwrite($fp,"Subject: $subject\r\n");
fwrite($fp,"\r\n");
fwrite($fp,"$text\r\n\r\n");
fclose($fp);
}
hope that helps.
-----Original Message-----
Sent: 24 May 2004 10:14
Subject: [PHP-WIN] windows mail problem
Hi there,
I've been having difficulty sending emails from Windows machines. I've
seen this problem in a few places before but I can't seem to fix it on
mail(): "sendmail_from" not set in php.ini or custom "From:" header missing
$headers = "From: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: My Application";
$headers);
This has worked on my linux server before. It is saying I haven't set a
[mail function]
; For Win32 only.
SMTP = localhost
The mail server is running and should be accepting connections. I've
tried the IIS SMTP server and also Argosoft, set both of them to accept
connections but it doesn't seem to get as far as the SMTP server.
I've tried it on my local machine (XP Pro, IIS 5, PHP 4.3.6) and on the
production server (Win 2003, IIS 6, PHP 4.3.6). I've restarted and done
all the things I've found suggested for this problem but no joy.
Can anyone help?
Thanks for your time,
Andy Tawse.
--
Andy Tawse | Head Programmer
New Media Collective | www.newmediacollective.com
***@newmediacollective.com
0870 4202313 | 07958 578399
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...