user90210
user90210

Reputation: 115

Sending emails using XAMPP and PHP using Mac Yosemite

I am really confused on where to start with sending emails. I have search the web but the amount of content available for different packages and softwares has really confused me. I was wondering if anyone here had a simple or knows of a simple tutorial of how i can send an email using xampp.

Im new to using local host and so far have only used MySQL and Apache from xampp to load and view my php files for an application.

I would really appreciate it if anyone could help me start setting up XAMPP to send emails when i use the php.

Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!

is this link any good? http://www.websnippetz.com/2013/01/send-email-from-xampp-localhost.html Many are using SendMail package with XAMPP but i can't find a download for that.

anyone tried anything which worked for them?

please help a very confused developer guys!

Upvotes: 0

Views: 1783

Answers (2)

prodigitalson
prodigitalson

Reputation: 60413

Some sites suggest a separate server is needed for emails such as PHPMailer while others suggest a few config changes need making like changing in the php.ini files which I'm very cautious to change incase my whole xampp crashes!

PHPMailer is not a server it is a library. People often recommend using a Mail library because the built mail functions are very low level and hard to work with. Because they are modeled after using sendmail from the commandline.

If you want to send via SMTP, use attachments, or other things it can be difficult or impossible to do with mail() directly.

Personally I recommend using SwiftMail over PHP mailer. IMO, it's more modern, easier to use, and has a better API, and depending on which PHP F/OSS projects you are used to using or contributing to its more common and the standard.

Overall there are 2 parts to sending mail from PHP:

  1. Setup of the actual mail server on a system (local or otherwise)
  2. The configuration of PHP to use that mail server.

To setup the mail function you need to install and configure a mail server locally in order to fulfill item (1). This should already be included and set up on OSX. So to fulfill item (2) you need to configure PHP via the INI to use that mail server by changing the sendmail_path.

Now if you want to use a library, which I recommend you need to get that source into your project and then use it appropriately. For the example we will use SwiftMailer, with SMTP transport via a gmail account:

require_once 'PATH/TO/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.googlemail.com', 465, 'ssl')
  ->setUsername('[email protected]')
  ->setPassword('secret');

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

$message = Swift_Message::newInstance('My SMTP Message')
  ->setFrom(array('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => 'A name'))
  ->setBody('Plain Text Message Body');

$mailer->send($message);

Upvotes: 1

René Höhle
René Höhle

Reputation: 27305

To send emails from your localhost your need an Email-Server like postfix or Exim or you send your E-Mails over SMTP what is described on that site from your link.

The easiest way is to use an abstraction layer like Swift Mailer

http://swiftmailer.org/docs/sending.html

Here you have a lot of possibilities to send E-Mails. Another solution is to install a local Mailserver and fetch all sending E-Mails. In MAMP Pro for example you have an integrated Mailserver.

http://blog-en.mamp.info/2009/09/how-to-sending-emails-with-mamp-pro.html

Upvotes: 0

Related Questions