我使用PHP,我的机器上有mamp。我想在我的PHP代码中发送电子邮件:
<?php
$to = "recipient@example.com";
$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>");
}
?>
如何在我的mac机器上免费配置邮件服务器?
答案 0 :(得分:10)
以下完成了这项工作。请参阅来源here。
sudo emacs /System/Library/LaunchDaemons/org.postfix.master.plist
。<key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/>
代码前添加</dict>
。sudo postfix start
。检查SMPT是否正在运行:telnet localhost 25
答案 1 :(得分:0)
试试这个 - http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
如果您希望SMTP服务器从OSX发送邮件,这可能有所帮助(实际上没有尝试过,但似乎可以完成这项工作) - http://email.about.com/cs/sendmail/gr/sendmail_enable.htm
希望有所帮助!
答案 2 :(得分:0)
Sending Mail from PHP Using SMTP Authentication - Example:
<?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>");
}
?>
Sending Mail from PHP Using SMTP Authentication and SSL Encryption - Example:
<?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 = "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>");
}
?>
答案 3 :(得分:0)
CommandLineFu可以使用这一个衬垫在端口25上运行SMTP服务器:
sudo python -m smtpd -n -c DebuggingServer localhost:25
这将在本地计算机上运行伪造的smtp服务器。它不会发送任何内容,但会将其转储到控制台。