使用PHP从Localhost发送邮件

时间:2011-12-15 11:38:33

标签: php

如何使用PHP从localhost发送Mail?

从localhost发送邮件到远程服务器

我正在使用wamp服务器,OS windows Xp。

任何人都可以告诉我这个问题

提前谢谢你

2 个答案:

答案 0 :(得分:2)

Windows :您需要在localhost上配置SMTP。更多info

编辑:

Linux: How to send email from localhost using PHP on Linux

答案 1 :(得分:0)

有一个Gmail帐户?是?凉!因为这对您来说是最简单的解决方案。如果没有,您可以使用此库连接到任何其他SMTP服务器。我们使用Gmail从我们的PHP脚本发送电子邮件,这里是:

从此处下载SwiftMailer库:http://swiftmailer.org/download

# get the library
require_once 'Swift/lib/swift_required.php';

# setup the transport

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
  ->setUsername('yourusername@gmail.com')
  ->setPassword('yourpassword');

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

# create our message

$message = Swift_Message::newInstance('Hello World!')
  ->setFrom(array('from@email.com' => 'Skynet'))
  ->setTo(array('to@email.com' => 'Terminator'))
  ->setBody('What would you like to say in the email?');

# send the message! hooray!

$mailer->send($message);
相关问题