dongweishi2028 2008-12-16 14:08
浏览 93
已采纳

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

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("no-reply@domain.com");
$mail->setReturnPath("webmaster@domain.com");

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.

  • 写回答

1条回答 默认 最新

  • dongxie1907 2008-12-16 19:03
    关注

    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 <sender@example.com>";
    $to = "Ramona Recipient <recipient@example.com>";
    $subject = "Hi!";
    $body = "Hi,
    
    How 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>");
     }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击