Configure mail server to work with PHP

扶醉桌前 提交于 2019-11-29 18:09:47

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.

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);
}

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. =)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!