11

I work with PHP and I have mamp on my machine. I would like to send emails within my PHP code:

<?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>");
  }
 ?>

How can I configure a mail server for free on my mac machine ?

0x90
  • 39,472
  • 36
  • 165
  • 245

4 Answers4

15

The following did the job. See source here.

  1. Edit file: sudo emacs /System/Library/LaunchDaemons/org.postfix.master.plist.
  2. Add <key>RunAtLoad</key> <true/> <key>KeepAlive</key> <true/> before the closing </dict> tag.
  3. Run sudo postfix start.

Check that SMPT is running: telnet localhost 25

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • Even though I'm across after a long time, please update the source. It seems to not work. – Ameed Aabidi Dec 27 '17 at 04:32
  • Syed, I didn't write the missing article. Feel free finding a replacement source. – AlikElzin-kilaka Dec 27 '17 at 06:49
  • 4
    I didn't have that file, although I did have /System/Library/LaunchDaemons/com.apple.postfix.master.plist It didn't have edit permission so I tried just starting the service, which seemed to work by itself. – micseydel Oct 30 '18 at 16:45
14

Option 1:

CommandLineFu had this one liner to run an SMTP server on port 25:

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.

Option 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.

[http://nilhcem.com/FakeSMTP/][1]

Vega
  • 27,856
  • 27
  • 95
  • 103
Devender Goyal
  • 1,450
  • 3
  • 18
  • 26
0

Try this - 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

Hope that helps!

Blueberry
  • 2,211
  • 3
  • 19
  • 33
0

Are there any smtp server i can install on linux mac ?

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>");
  }
 ?>

Related topics:

Community
  • 1
  • 1
0x90
  • 39,472
  • 36
  • 165
  • 245