IIS6.0 / Exchange 6.5 / PEAR / php mail

EdFred

Taxi to Parking
Joined
Feb 25, 2005
Messages
30,230
Location
Michigan
Display Name

Display name:
White Chocolate
<?php
include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "mailaddress";
$headers["From"] = "mailaddress";
$headers["To"] = "mailaddress";
$headers["Subject"] = "Test Message";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "localhost";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "username";
$smtpinfo["password"] = "password";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
if (PEAR::isError($mail_object))
{
echo "<p>" . $mail_object->getMessage() . "</p>";
}
else
{
echo "<p>Message successfully sent (really new)!</p>";
}
echo '<br /><br/>';
print_r($mail_object);
echo '<br /><br/>';
echo $mail_object->getMessage();
?>

Ok, so I run this script (with appropriate mail/user/password) and it says the mail is sent successfully, but it doesn't send.

I am using Server2003 with IIS6.0 and Exchange Manager 6.5.6944.0
I have messed with all the relays, authentications, etc...

Any ideas on why it won't talk to the SMTP server and actually send the mail. Google has been of no help.
 
<?php
include("Mail.php");
/* mail setup recipients, subject etc */
$recipients = "mailaddress";
$headers["From"] = "mailaddress";
$headers["To"] = "mailaddress";
$headers["Subject"] = "Test Message";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "localhost";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "username";
$smtpinfo["password"] = "password";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
if (PEAR::isError($mail_object))
{
echo "<p>" . $mail_object->getMessage() . "</p>";
}
else
{
echo "<p>Message successfully sent (really new)!</p>";
}
echo '<br /><br/>';
print_r($mail_object);
echo '<br /><br/>';
echo $mail_object->getMessage();
?>

Ok, so I run this script (with appropriate mail/user/password) and it says the mail is sent successfully, but it doesn't send.

I am using Server2003 with IIS6.0 and Exchange Manager 6.5.6944.0
I have messed with all the relays, authentications, etc...

Any ideas on why it won't talk to the SMTP server and actually send the mail. Google has been of no help.

Blegh, you're doing it the hard way, man.

Set up php.ini properly, and you can get away with:

Code:
$fromemail =  YOUREMAIL;
$to = TOADDRESS;
$subject = SUBJECT;
$body = BODY;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";	
$headers .= "From: $fromemail";

if (mail($to,$subject,$body,$headers))
{
  echo "Success";
}
else
{
  echo "Fail";
}


Oh, and let me explain - screw PEAR. I'll be unpopular for saying it, but aside from a few niche things, screw it right up its PEAR shaped bum.
 
Ed, first off, have you looked in the Exchange logs to see what it says?

Second, get rid of whatever Mail class you're using there and use: http://swiftmailer.org/

Use SwiftMailer..it is basically the standard of PHP mailers and does a *REALLY* good job at getting the headers right (better than what Nick posted above).

Assuming that the PHP class you're using even work, who knows if it does, and PHP says it connected and delivered the message...If all that happened, then, refer to the Exchange logs.
 
Back
Top