views:

96

answers:

3

Hi.

My current project is a form that receives input from a user. After I receive that data, I must send a warning/report to a few email addresses, including the user who inserted the data. Almost everything is up and running, Apache, MySQL, PHP.

Now I never installed a mail server, to work with PHP so I'm kinda lost.

My employer has MS Exchange 2007 on his server installed. Should I use it, and how would I start to configure php to work with it? What do I need from the Exchange 2007 (parameters)?

If not, would you recommend installing a new mail server for just this purpose on the same machine that has Apache+MySQL+PHP?

I am more inclined to use the already present Exchange server, but I read at some online articles that it's not the easiest thing to configure.

UPDATE:

<?php
include("Mail/Mail.php");
/* mail setup recipients, subject etc */
$recipients = "[email protected]";
$headers["From"] = "[email protected]";
$headers["To"] = "[email protected]";
$headers["Subject"] = "User feedback";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "mail.name.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "username";
$smtpinfo["password"] = "pass";
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
?>

Using this example above I can't send mail through Exchange 2007.

I get no errors output on the page, so I'm kinda lost. Don't know what is wrong.

UPDATE: Can anyone recommend a good mail server?

A: 

Exchange supports regular SMTP mail delivery (it has to, otherwise it couldn't talk to the rest of the email world), so just point your PHP's configuration at the Exchange server as if it was a regular mail server.

There's some .ini settings for mail, documented here: http://php.net/manual/en/mail.configuration.php#ini.smtp

Assuming the exchange server doesn't require authentication and will accept mail from your server, that's all that should be required.

followup:

did you read the docs on the Mail package? the send() method returns TRUE on success, or a PEAR_Error object on failure. It will contain any details about the send attempt's failure, most likely you'd want $PEAR_Error:message. Full details here: http://pear.php.net/package/PEAR/docs/1.9.1/PEAR/PEAR_Error.html. Change your code from

$mail_object->send($recipients, $headers, $mailmsg);

to

$status = $mail_object->send($recipients, $headers, $mailmsg);
if ($status !== TRUE) {
    die("Error sending mail: " . $status::message);
}
Marc B
When you mention authentication what do mean? Shouldn't in normal circumstances ask for that?
elvispt
Some mail servers you have to "log in" to before they'll have anything to do with you. For instance, most mail servers won't allow mail to be sent through them from "outside" their own network, but will allow if you authenticate yourself to it, to prove you're a "local" user.
Marc B
Can't get it work. check edit above.
elvispt
If you can't get the PEAR package to work, you can try PHPMailer: http://phpmailer.worxware.com simple and free and works very well.
Marc B
I'm using PHPmailer. Thanks for the hint.
elvispt
A: 

It's very likely you need authentication. This could be as simple as providing your username and password to the email account you want to send from.

If that's the case, I'd suggest you use the PEAR Mail extension. There's a function called factory that allows you to do authentication with an smtp server. (Including SSL encryption, if you discover your server needs it)

http://pear.php.net/manual/en/package.mail.mail.factory.php

Your code would look a little like this:

$smtp = Mail::factory('smtp',
  array ('host' => $host,
   'port' => $port,
   'auth' => true,
   'username' => $username,
   'password' => $password));

$mail = $smtp->send($to, $headers, $body);

Installing PEAR extensions on your server is not as hard as you might think.

rod
I'm hunting around the web now, for PEAR and how to install it. Will reply with the outcome later. :)
elvispt
Just my luck. It seems that php_phar.dll was supposed to be present in the ext directory, but in my case it wasn't. I'm getting all sorts of error when trying to install pear. :S
elvispt
A: 

Ok. Got it to work. Phew.

I found out the reason, after reading alot. It was regarding a relay problem with the smtp exchange server.

But I would have never got there if it wasn't for you people. xD

Thank you all. =)

elvispt