我已经在本地笔记本上配置了一个php/mysql应用程序,使用iis7进行测试。我使用php mail()在服务器上使用localhost smtp服务发送电子邮件,并希望在本地复制以进行测试。(它已经在服务器上运行了很长一段时间了,所以我只想在本地进行复制以进行测试。)
使用technet文章:http://technet.microsoft.com/en-us/library/cc772058(WS.10).aspx我能够配置我的SMTP设置,但是我仍然不能发送电子邮件。
我已经回收服务器很多次,但没有任何效果。
我运行了一个netstat -an,没有监听port25的东西--我还需要做些什么才能让smtp服务监听port25呢?
我收到的错误是:
PHP警告:邮件() function.mail:未能连接到"localhost“端口25的邮件服务器,在php.ini中验证"smtp_port”和“smtp_port”设置或使用ini_set()
php.ini:
SMTP = localhost
smtp_port = 25发布于 2011-08-27 08:59:31
您可以使用类似于smtp4dev (http://smtp4dev.codeplex.com/)的东西来代替iis进行测试。对我来说很有魅力。
发布于 2011-08-27 13:27:30
Windows 7不提供SMTP服务。所以你必须使用第三方产品。这一直是一个众所周知的问题,但不知道为什么你没有找到它在互联网上搜索。
发布于 2012-05-04 02:15:44
我同意行动计划。现在还不清楚W7 (甚至是终极版)没有SMTP服务器(我很肯定我们在Vista 64终极版甚至XP上都有),所以您必须识别要使用的服务器,无论是本地的还是远程的。
如果服务器没有使用授权,那么这应该可以正常工作,而不必与IIS7或IIS7 Express混为一谈:
$smtpserver = 'host.domain.tld';
$port = 25;
$from = 'mailbox@domain.tld';
$replyto = $from;
$headers = 'From: ' . $from . "\r\n" . 'Reply-To: ' . $replyto . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$to = 'mailbox@domain.tld';
$subject = 'Test Message';
ini_set('SMTP', $smtpserver);
ini_set('smtp_port', $port);
$message = wordwrap("Hello World!", 70);
$success = mail($to, $subject, $message, $headers);如果服务器使用的是明文授权(而不是TLS/SSL),那么添加凭据可能有效,具体取决于PHP的版本:
ini_set('username', 'yourusername');
ini_set('password', 'yourpwd');如果服务器强制使用TLS/SSL来连接凭据,就像GMail一样,那么Sourceforge xpm4包是一个简单的解决方案。您可以在GMail中使用它的两种方法(这些方法直接从包中提供的示例中获得):
// manage errors
error_reporting(E_ALL); // php errors
define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
// path to 'MAIL.php' file from XPM4 package
require_once '../MAIL.php';
// initialize MAIL class
$m = new MAIL;
// set from address
$m->From('username@gmail.com');
// add to address
$m->AddTo('client@destination.net');
// set subject
$m->Subject('Hello World!');
// set HTML message
$m->Html('<b>HTML</b> <u>message</u>.');
// connect to MTA server 'smtp.gmail.com' port '465' via SSL ('tls' encryption)
// with authentication: 'username@gmail.com'/'password'
// set the connection timeout to 10 seconds, the name of your host 'localhost'
// and the authentication method to 'plain'
// make sure you have OpenSSL module (extension) enable on your php configuration
$c = $m->Connect('smtp.gmail.com', 465, 'username@gmail.com', 'password', 'tls', 10,
'localhost', null, 'plain')
or die(print_r($m->Result));
// send mail relay using the '$c' resource connection
echo $m->Send($c) ? 'Mail sent !' : 'Error !';
// disconnect from server
$m->Disconnect();IIS7快捷(我正在使用的) FastCGI PHP模块安装时启用了OpenSSL扩展支持。以上允许您在消息内容中使用HTML标记。使用xpm4包的第二种方法如下所示,仅用于文本消息(同样,示例来自包源):
// manage errors
error_reporting(E_ALL); // php errors
define('DISPLAY_XPM4_ERRORS', true); // display XPM4 errors
// path to 'SMTP.php' file from XPM4 package
require_once '../SMTP.php';
$f = 'username@gmail.com'; // from (Gmail mail address)
$t = 'client@destination.net'; // to mail address
$p = 'password'; // Gmail password
// standard mail message RFC2822
$m = 'From: '.$f."\r\n".
'To: '.$t."\r\n".
'Subject: test'."\r\n".
'Content-Type: text/plain'."\r\n\r\n".
'Text message.';
// connect to MTA server (relay) 'smtp.gmail.com' via SSL (TLS encryption) with
// authentication using port '465' and timeout '10' secounds
// make sure you have OpenSSL module (extension) enable on your php configuration
$c = SMTP::connect('smtp.gmail.com', 465, $f, $p, 'tls', 10) or die(print_r($_RESULT));
// send mail relay
$s = SMTP::send($c, array($t), $m, $f);
// print result
if ($s) echo 'Sent !';
else print_r($_RESULT);
// disconnect
SMTP::disconnect($c);在本文发布之日,上述两种方法都与GMail一起工作,使用IIS7,无需进行任何额外的配置。
https://stackoverflow.com/questions/7213318
复制相似问题