php 如何在 Mac OS X 上设置 SMTP 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11174682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to setup an SMTP server on Mac OS X?
提问by 0x90
I work with PHP and I have mampon my machine. I would like to send emails within my PHP code:
我使用 PHP,我的机器上有mamp。我想在我的 PHP 代码中发送电子邮件:
<?php
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
How can I configure a mail server for free on my mac machine ?
如何在我的 mac 机器上免费配置邮件服务器?
回答by AlikElzin-kilaka
The following did the job. See source here.
下面的工作完成了。请参阅此处的来源。
- Edit file:
sudo emacs /System/Library/LaunchDaemons/org.postfix.master.plist. - Add
<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>before the closing</dict>tag. - Run
sudo postfix start.
- 编辑文件:
sudo emacs /System/Library/LaunchDaemons/org.postfix.master.plist. - 添加
<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>在结束</dict>标记之前。 - 运行
sudo postfix start。
Check that SMPT is running: telnet localhost 25
检查 SMPT 是否正在运行: telnet localhost 25
回答by Devender Goyal
Option 1:
选项1:
CommandLineFu had this one liner to run an SMTP server on port 25:
CommandLineFu 有一个 liner 在端口 25 上运行 SMTP 服务器:
sudo python -m smtpd -n -c DebuggingServer localhost:25
This will run a fake smtp server on your local machine. It won't send anything, but will dump it to the console.
这将在您的本地机器上运行一个假的 smtp 服务器。它不会发送任何内容,但会将其转储到控制台。
Option 2:
选项 2:
Incase, you are not comfortable with command line then FakeSMTP is a Free Fake SMTP Server with GUI for testing emails in applications easily. It is written in Java. It is very nice and easy to use.
如果您对命令行不满意,那么 FakeSMTP 是一个带有 GUI 的免费假 SMTP 服务器,用于轻松测试应用程序中的电子邮件。它是用Java编写的。它非常好且易于使用。
[http://nilhcem.com/FakeSMTP/][1]
[ http://nilhcem.com/FakeSMTP/][1]
Kindly upvote the answer if it help :)
如果有帮助,请为答案点赞:)
回答by Blueberry
Try this - http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
试试这个 - http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
and if you want an SMTP server to send mail from on OSX, this may help (havent actually tried it, but seems like it could do the job) - http://email.about.com/cs/sendmail/gr/sendmail_enable.htm
如果您希望 SMTP 服务器从 OSX 上发送邮件,这可能会有所帮助(尚未实际尝试过,但似乎可以完成这项工作)- http://email.about.com/cs/sendmail/gr/sendmail_enable .htm
Hope that helps!
希望有帮助!
回答by 0x90
Are there any smtp server i can install on linux mac ?
我可以在 linux mac 上安装任何 smtp 服务器吗?
Sending Mail from PHP Using SMTP Authentication - Example:
<?php
require_once "Mail.php";
$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$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>");
}
?>
Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example:
使用 SMTP 身份验证和 SSL 加密从 PHP 发送邮件 - 示例:
<?php
require_once "Mail.php";
$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'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>");
}
?>

