0

I was having trouble sending mail in my localhost xampp using this tutorial. I just researched on this same topic at How to configure XAMPP to send mail from localhost?

I have tried both the links but mail function is not working instead of this every mail function is storing as notepad file inside the xampp/mailoutput folder. Whenever I tried to send a mail those things are storing as notepad files in the mailoutput folder inside the xampp folder.

I do not know what the problem was. I have changed my php.ini and sendmail.ini files in xampp.

php.ini as follows:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini as follows:

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

Can anybody help me to solve this issue?

Community
  • 1
  • 1

1 Answers1

1

Download PHPMailer library from https://github.com/PHPMailer/PHPMailer.

<?php
require 'PHPMailer/PHPMailerAutoload.php';
 
$mail = new PHPMailer;
 
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'ansuman@gmail.com';
$mail->Password = '******';
$mail->SMTPSecure = 'tls';
 
$mail->From = 'ansuman@gmail.com';
$mail->FromName = 'Raj Amal';
$mail->addAddress('ansuman@ansuman.com', 'ansuman');
 
$mail->addReplyTo('ansuman@gmail.com', 'ansuman');
 
$mail->WordWrap = 50;
$mail->isHTML(true);
 
$mail->Subject = 'Using PHPMailer';
$mail->Body    = 'Hi Iam using PHPMailer library to sent SMTP mail from localhost';
 
if(!$mail->send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent'; The SMTP host of Gmail is smtp.gmail.com. It will vary for Outlook and Yahoo mail. The to Address should be set in addAddress(). I think it will be really helpful for you guys.

ansuman chauhan
  • 427
  • 2
  • 9
  • i tried with your solution ..its showing error like : Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting – Harshitha Naidu K Aug 28 '15 at 05:32
  • If not yet, try this:
1. Open xampp->php->php.ini 
2. Search for extension=php_openssl.dll 
3. The initial will look like this ;extension=php_openssl.dll 
4. Remove the ';' and it will look like this extension=php_openssl.dll 
5. If you can't find the extension=php_openssl.dll, add this line extension=php_openssl.dll.
 6. Then restart your Xampp. – ansuman chauhan Aug 28 '15 at 05:34
  • i did the same what u said ..even this is not working – Harshitha Naidu K Aug 28 '15 at 05:39
  • How does using phpmailer actually solve the problem? Magic? – John Conde Aug 28 '15 at 11:37
  • still it is not working i tried in so many ways..but tell me one thing will mail function work in localhost or not ? – Harshitha Naidu K Aug 28 '15 at 11:49
  • Defiantly it will work wait , i will provide you exact code for that... – ansuman chauhan Aug 28 '15 at 11:50
  • Can anybody please help me out in this .Form one week i was trying on this it is not happening . i have gone through all the solutions which were provided by stackoverflow and others as well.But it is not happening . – Harshitha Naidu K Aug 31 '15 at 07:19