0

I am unable to send mails through localhost Xampp even after making changes in php.ini and sedmail.php files as per THIS. I have adoubt in sendmail.php file what email & PassWord to give here;

auth_username=   
auth_password=  

Please somebody get me through this.

Community
  • 1
  • 1
Anjels
  • 3
  • 1
  • 4

2 Answers2

0

Let we resolve this issue by follow some steps.

1. Make sure error reporting is enabled and set to report all errors(use code in .php file)

error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

2. Check your server's mail logs

Your localhost should be logging all attempts to send emails through it. The location of these logs will user's root directory under logs. Inside will be error messages the server reported, if any, related to your attempts to send emails.

3. Make sure you have a mail server set up on localhost

If you are developing on your local workstation using XAMPP, an email server is probably not installed on your workstation. Without one, PHP cannot send mail by default.

You can overcome this by installing a basic mail server. For Windows you can use the free Mercury Mail.

You can also use SMTP to send your emails. See this answer to re-check how to do this.

4. Check to see if mail() returns true or false with message

Please use below code and let me know what happen. This code will display actual error message and we can resolve this issue.

Replace

mail($to, $subject, $message, $headers);

With

$mailReturn = mail($to, $subject, $message, $headers);
print('<pre>');
print_r($mailReturn);
print('</pre>');
exit();

If above 3 steps done perfect but no success then follow step 4. Let me know what this code print.

5. SMTP settings(in php.ini) for send mail from localhost

If you are using Gmail then you got lucky. Gmail lets us use their SMTP provided that you will have to authenticate it using your own username and password. To use Gmail SMTP the values will be like below:

//Set the hostname of the mail server
$mail->Host = "smtp.gmail.com";

//enable this if you are using gmail smtp, for mandrill app it is not required
//$mail->SMTPSecure = 'tls';

//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "YOUR.ID@GMAIL.COM";
//Password to use for SMTP authentication
$mail->Password = "YOUR_PASSWORD";

Or, if you don't want to use your Gmail account then I would suggest to create one account on Mandrill and get your SMTP host, username and password from there. I have tested both gmail and mandrill and they are working pretty good.

//Set the hostname of the mail server
$mail->Host = "smtp.mandrillapp.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "YOUR_REGISTER_EMAIL@MANDRILL.COM";
//Password to use for SMTP authentication
$mail->Password = "YOUR_PASSWORD";

Make sure all variables value are checked and change if require.

Community
  • 1
  • 1
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
0

You can use SMTP mail sending library and try that function to send the mail from localhost

H.Dave
  • 21
  • 1