Asked  7 Months ago    Answers:  3   Viewed   34 times

I'm using WampServer on Windows to test a site. I have a registration system where users get a confirmation email.

Is it possible to send emails from a localhost?

 Answers

98

If you want to send emails from localhost directly, you need to install a Mail Transport Agent (MTA), or if you like, a SMTP service.

IIS provides one. You can otherwise find some others on Google.

You can also change your php.ini mail settings. This won't use localhost per say to send emails, but a relay host that will allow you to send emails from a PHP script.

Wednesday, March 31, 2021
 
IvanH
answered 7 Months ago
15

Try using SMTP server with gmail.

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

or else there are many PHP mailer library. which simplifies things for you and makes it so easier to use. my fav is swift mailer. the best part about is you don't have to mess with your core php configuration file and the documentation too is very easy to read.

for example if you want to send a mail using PHP's swift mailer library it is as simple as.

require_once 'lib/swift_required.php';

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

// 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);

you can refer the documentation for more information on the official website http://swiftmailer.org/docs

Wednesday, March 31, 2021
 
EurekA
answered 7 Months ago
59

Try this

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
auth_username=[email]@gmail.com
auth_password=[email password]
pop3_server=
pop3_username=
pop3_password=
force_sender=[email]@gmail.com
force_recipient=
hostname=smtp.gmail.com

php.ini

[mail function]

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"
mail.add_x_header=Off
Friday, July 30, 2021
 
Nopiforyou
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :