使用 HTML Mime Mail for PHP 发送电子邮件,但需要通过 Exchange 服务器进行身份验证

发布于 2024-07-11 03:36:29 字数 1348 浏览 3 评论 0原文

首先,服务器:在 Windows 2003 Server sp2 上运行的 Exchange 2003 sp2

我有一个脚本,可以将电子邮件发送到两个电子邮件帐户,一个名为 Students@,另一个名为 fs@(教职员工)。 我们将这两个电子邮件帐户设置为仅接受交换服务器上经过身份验证的用户传入的电子邮件,以避免垃圾邮件。 所以现在脚本发送的电子邮件不成功。 我作为合法用户拥有返回路径电子邮件,但它未经身份验证。 我注意到,当我尝试通过我的邮件客户端(Apple 的 Mail.app)发送测试时,由于我通过他们的 IMAP 服务器而不是通过 Exchange 使用电子邮件,所以我的电子邮件也失败了。

以下是发送电子邮件的代码:

$mail = new htmlMimeMail();
$message = $today.$announcements.$food.$upcoming;
$mail->setHTML($message);
$mail->setSubject($subject);
$mail->setSMTPParams('mail.domain.com', 25, true, 'user', 'pass');
$mail->setFrom("[email protected]");
$mail->setReturnPath("[email protected]");

if($message)
    $mailresult = $mail->send(array($emailto));

我从未使用 PHP 的 HTML Mime Mail (http://www.phpguru.org/static/mime.mail.html) 类之前。 任何帮助,将不胜感激。

也许还有另一个 PHP 类可以轻松地允许使用 Exchange 服务器进行身份验证?

编辑:是否有任何 php 邮件类可以通过交换服务器正确进行身份验证?

另一个编辑:Exchange Server 使用 NTLM 身份验证并使用 Active Directory。 希望这可以帮助。

First off, the server: Exchange 2003 sp2 running on Windows 2003 Server sp2

I have a script that sends email to two email accounts, one called students@ and the other being fs@ (faculty/staff). We are setting both those email accounts to only accept incoming email by authenticated users on the exchange server, to spare ourselves from spam/junk mail. So right now the emails being sent by the script are not successful. I have the return-path email as a legit user, but it is not authenticated. I noticed that when I tried sending a test via my mail client (Apple's Mail.app) and since I use email through their IMAP server and not through exchange, my email failed as well.

Here is the code for sending the email:

$mail = new htmlMimeMail();
$message = $today.$announcements.$food.$upcoming;
$mail->setHTML($message);
$mail->setSubject($subject);
$mail->setSMTPParams('mail.domain.com', 25, true, 'user', 'pass');
$mail->setFrom("[email protected]");
$mail->setReturnPath("[email protected]");

if($message)
    $mailresult = $mail->send(array($emailto));

I have never authenticated with an exchange server using the HTML Mime Mail for PHP (http://www.phpguru.org/static/mime.mail.html) class before. Any help would be appreciated.

Maybe there is another PHP class that easily allows authentication with an Exchange server?

EDIT: Are there any php mail classes out there that authenticate properly with an exchange server?

Another EDIT: The Exchange Server uses NTLM authentication and uses Active directory. Hope this helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-07-18 03:36:29

Exchange 支持标准的 SMTP Auth 机制,所以我会使用它。 以下是使用 Pear::Mail 的示例。 about.com/od/emailprogrammingtips/qt/et073006.htm" rel="noreferrer">此处。

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

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

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

Exchange supports the standard SMTP Auth mechanism, so I would use that. Here is an example using Pear::Mail from here.

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

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

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文