1

I'm setting up smtp on IIS web server using php

In the php.ini file the smtp section as follow:

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

auth_username = my_dyndns_username
auth_password = pwd

sendmail_from = no-reply@website.com

The problem is that when I try to call the mail() function the smtp server says

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

where can I tell IIS (or php) the username and password in order to be authenticated on dyndns server?

Dario

Dario Rusignuolo
  • 2,090
  • 6
  • 38
  • 68
  • it looks like you'll need to either use a mail library or write your own to talk directly to the mail server – Sam Dufel Feb 11 '13 at 23:25

2 Answers2

1

I found swift mailer to be a solution form my problem.

with this simple script I have everything works

$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 is the book on how to do with other functions/parameters

Dario Rusignuolo
  • 2,090
  • 6
  • 38
  • 68
0

To use SMTP Authentication with PHP you'll want to use the Mail PEAR extension ... here is a nice post telling you how to use it.

Basically, you'll need to install the extension (windows instructions) and then configure a bit of code something like this (from the post above):

<?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>");
  }
 ?>
Justin Jenkins
  • 26,590
  • 6
  • 68
  • 1,285
  • but how to do that without external libraries? I mean, I want to use pure php.ini configuration... is that possible? – Dario Rusignuolo Feb 11 '13 at 23:49
  • 1
    Good luck getting that to work without the `PEAR` lib ... I've never seen it done. BTW, `PEAR` isn't really an external lib, it's extensions (i.e. PHP functions) and it's hosted by the people that make PHP http://pear.php.net/ --- it's not unlike writing your own function to do it, except their functions are likely to be better :) – Justin Jenkins Feb 12 '13 at 00:14