0

I need to send mail through localhost (in both LAMP and WAMP) using PHP. How can I do this? I read many tutorials on this requirement and yet didn't get any solutions. I read that using SMTP we can do this but how will I get the credentials for using SMTP? Hope that someone will help me to do this.

Thank you in advance.

Jenz
  • 8,280
  • 7
  • 44
  • 77
  • read this http://stackoverflow.com/questions/13137558/sending-mail-from-localhost-using-php and http://stackoverflow.com/questions/15267423/php-send-mail-in-localhost – VIVEK-MDU Aug 09 '13 at 05:04
  • You need to clear up exactly what problem you're having if you're looking for a more specific answer. – Drew Khoury Aug 09 '13 at 07:06

1 Answers1

2

There are many ways to send mail in PHP.

You can use PHPs mail function.

http://php.net/manual/en/function.mail.php

<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");

// Send
mail('caffeinated@example.com', 'My Subject', $message);
?>

SwiftMailer is also worth looking at

It has lots of features for sending mail in different ways (transport types, attachments etc), and it's easy to use.

http://swiftmailer.org/

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

require_once 'lib/swift_required.php';

// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
  ->setUsername('your username')
  ->setPassword('your password')
  ;

/*
You could alternatively use a different transport such as Sendmail or Mail:

// Sendmail
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

// Mail
$transport = Swift_MailTransport::newInstance();
*/

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);
Drew Khoury
  • 1,370
  • 8
  • 21