2

I am trying to send email from localhost but somehow mail is not being send to any email address. I am trying to configure email from localhost and found some solution which are pointing me to configure with sendemail server which is \xampp\sendmail\sendmail.exe. My problem is that I can not found sendmail folder in my xampp directory. So can not configure sendmail.

I am using xampp v3.2.1

Can please anyone tell me that why I don't have sendmail folder in xampp dir?

Imran Mushtaq
  • 147
  • 1
  • 2
  • 10

2 Answers2

2

You must have SMTP Server, so you can send mails
Alternative solutions is to use externals one, like gmail for example

First you should have a valid gmail credetials, after that go to php.ini and configure it as follow :

[mail function]
SMTP      = ssl://smtp.gmail.com
smtp_port = 465
username  = YOUR_GOOGLE_USERNAME
password  = YOUR_GOOGLE_PASSWORD

Restart your web server and try with the classic php mail() function

Here is my yml SMTP Server configuration that i have used for a symfony project :

parameters:
    mailer_transport: gmail
    mailer_host     : 127.0.0.1
    mailer_user     : anis.halayem@gmail.com
    mailer_password : ***my_gmail_password_secret***
    locale          : en

You can setup your own local SMTP Server local SMTP Server

__EDIT__

Try with PHPMailer : PHPMailer - A full-featured email creation
And the good thing with it, that it will let you debug what is causing troubles with sending mails using gmail smtp server

First thing : are you behind proxy ? if it's the case, you have to configure the HTTP_PROXY/HTTPS_PROXY environment variables
You can find useful documentations here and here

Now, you can create a php test script that you can launch directly via commands line or using a web server

<?php
require_once    ('PHPMailer-master/class.phpmailer.php');
require_once    ('PHPMailer-master/class.smtp.php');

$mail               = new PHPMailer();
$body               = "<h1> Sending HTML Mails using gmail</h1><p>it's great !!</p>";
$mail->IsSMTP();                                        // telling the class to use SMTP
$mail->SMTPDebug    = 1;                                // enables SMTP debug information (for testing)
$mail->SMTPAuth     = true;                             // enable SMTP authentication
$mail->SMTPSecure   = "tls";                            // sets the prefix to the servier
$mail->Host         = "smtp.gmail.com";                 // sets GMAIL as the SMTP server
$mail->Port         = 587;                              // set the SMTP port for the GMAIL server

$mail->Username     = "YOUR_GMAIL_ACCOUNT"  ;           // GMAIL username
$mail->Password     = 'YOUR_GMAIL_PASSWORD' ;           // GMAIL password

$mail->SetFrom('VALID_USER@gmail.com', 'Anis Halayem');
$mail->Subject    = "Test Send Mails";
$mail->MsgHTML($body);
$address = "VALID_USER@gmail.com";
$mail->AddAddress($address, "USER NAME");

// $mail->AddAttachment("images/phpmailer.gif");        // attachment
// $mail->AddAttachment("images/phpmailer_mini.gif");   // attachment

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else {
    echo "Message sent!";
}
Community
  • 1
  • 1
Halayem Anis
  • 7,654
  • 2
  • 25
  • 45
  • "You can setup your own local SMTP Server local SMTP Server" - Can I do without setting a SMTP Server locally? – Rupam Datta Feb 08 '16 at 11:13
  • @RupamDatta yes of course : just use an **external SMTP server** like gmail and follow the configuration to set up in **php.ini** file – Halayem Anis Feb 08 '16 at 12:24
  • I tried use gmail configuration but I failed to send emails. I get connections errors. I can share what I have tried so far with you. – Rupam Datta Feb 09 '16 at 06:19
  • I'm getting this error: 2016-02-09 08:50:56 SMTP ERROR: Failed to connect to server: No route to host (65) 2016-02-09 08:50:56 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting – Rupam Datta Feb 09 '16 at 08:58
  • so, i think that you should configure your `HTTP_PROXY` environment variable, make sure that your settings are correct : you must be able to `ping google.com` correctly before going further.... – Halayem Anis Feb 09 '16 at 09:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102977/discussion-between-rupam-datta-and-halayem-anis). – Rupam Datta Feb 09 '16 at 09:34
  • @RupamDatta do not forget the bounty :D ... it was a pleasure :) – Halayem Anis Feb 11 '16 at 08:06
1

I encountered the same problem.
It is very easy solve.
Just follow these steps:
First make sure that you are using Xampp v3.2.2 because that is the version I am using and about which I know.

  1. Copy and paste all the files "you" have created in htdocs folder anywhere on the pc.(so that they are not deleted).
  2. Uninstall Xampp.
  3. And then reinstall Xampp, but this time, DON'T UNCHECK THE "Fake Sendmail" option from the list when it asks "Select Components".
  4. And then follow the normal processes.

And, you are done. The Sendmail would be normally installed.

DarkGuy10
  • 55
  • 13