[英]setting smtp on php.ini with authentication
I'm setting up smtp on IIS
web server using php
我正在使用
php
在IIS
Web 服务器上设置 smtp
In the php.ini
file the smtp section as follow:在
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
The problem is that when I try to call the mail() function the smtp server says问题是,当我尝试调用 mail() 函数时,smtp 服务器说
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?我在哪里可以告诉 IIS(或 php)用户名和密码以便在 dyndns 服务器上进行身份验证?
Dario达里奥
I found swift mailer to be a solution form my problem.我发现swift mailer是我的问题的解决方案。
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这是关于如何处理其他函数/参数的书
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.要在 PHP 中使用
SMTP
身份验证,您需要使用 Mail PEAR
扩展名……这是一篇很好的文章,告诉您如何使用它。
Basically, you'll need to install the extension (windows instructions ) and then configure a bit of code something like this (from the post above):基本上,您需要安装扩展程序(windows 说明),然后配置一些类似这样的代码(来自上面的帖子):
<?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>");
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.