使用身份验证在php.ini上设置smtp

时间:2013-02-11 23:09:27

标签: iis-7 smtp php dyndns

我正在使用IIS

php网络服务器上设置smtp

php.ini文件中,smtp部分如下:

[mail function]
SMTP = outbound.mailhop.org
smtp_port = 25

auth_username = my_dyndns_username
auth_password = pwd

sendmail_from = no-reply@website.com

问题是当我尝试调用mail()函数时,smtp服务器会说

SMTP server response: 550 You must authenticate to use Dyn Standard SMTP

在哪里可以告诉IIS(或php)用户名和密码,以便在dyndns服务器上进行身份验证?

的Dario

2 个答案:

答案 0 :(得分:1)

我发现swift mailer是我问题的解决方案。

使用这个简单的脚本我一切正常

$transport = Swift_SmtpTransport::newInstance('outbound.mailhop.org', 25)
                ->setUsername('user')
                ->setPassword('pwd');

$mailer = Swift_Mailer::newInstance($transport);


$message = Swift_Message::newInstance()
        ->setSubject($sbj)
        ->setFrom($from)
        ->setReplyTo($replyTo)
        ->setTo($to)
        ->setBody($msg);

$result = $mailer->send($message);

here是关于如何处理其他功能/参数的书

答案 1 :(得分:0)

要使用PHP SMTP身份验证,您需要使用Mail PEAR扩展程序...这里有一个nice post,告诉您如何使用它。

基本上,您需要安装extensionwindows instructions),然后配置一些像这样的代码(来自上面的帖子):

<?php
 require_once "Mail.php";

 $from = "Sandra Sender <sender@example.com>";
 $to = "Ramona Recipient <recipient@example.com>";
 $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>");
  }
 ?>