Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

mysql - Configure mail server to work with PHP

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...