在Windows中从php发送来自localhost的电子邮件

时间:2012-04-06 13:54:36

标签: php email smtp localhost

我正在使用这个非常小的片段代码来测试电子邮件是否到达电子邮件目的地:

<?php
  mail('woodsy013@hotmail.com','Test mail','The mail function is working!');
  echo 'Mail sent!';
?>

但它似乎没有起作用。我正在使用WAMP。我安装了一个免费的SMTP服务器。我的php.ini文件配置如下:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.tools.sky.com
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = you@yourdomain

根据我提到的行动,我似乎没有收到woodsy130@hotmail.com的电子邮件。

我收到此错误:

Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 
Must issue a STARTTLS command first. ff2sm10904265wib.9 in 
C:\wamp\www\Derrysgc2\pages\pages\mailtest.php on line 2

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

尝试使用带有Gmail的SMTP服务器。

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

或者有很多PHP邮件库。它简化了您的工作,使其更易于使用。我最喜欢的是快捷邮件。最好的部分是你不必乱用你的核心php配置文件,文档也很容易阅读。

例如,如果您想使用PHP的swift邮件程序库发送邮件,就像它一样简单。

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password');

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself');

// Send the message
$result = $mailer->send($message);

您可以在官方网站http://swiftmailer.org/docs

上查阅文档以获取更多信息

答案 1 :(得分:1)

SMTP不应该指向您的SMTP服务器吗? (我假设smtp.tools.sky.com是您的提供商)。 sendmail_from也应该是正确的电子邮件地址。

另请注意,某些邮件提供商会阻止从动态IP地址发送的电子邮件。

相关问题