0

I have a problem with sending e-mails from localhost (XAMPP 3.2.1). I want to send e-mails using the Gmail inbox.

In my case, I did everything like in this tutorial:http://www.websnippetz.com/php/send-email-from-xampp-localhost/

sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourname@gmail.com
auth_password=gmailpassword
force_sender=yourname@gmail.com

php.ini

[mail function]

SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = yourname@gmail.com
sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\"-t"
mail.add_x_header = Off 

Then reboot the server.

My code for sending email:

<?php
 $to = "tome@example.com";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";
 if (mail($to, $subject, $body)) {
   echo("<p>Email successfully sent!</p>");
  } else {
   echo("<p>Email delivery failed…</p>");
  }
 ?>

After running the code - there is nothing in my mailbox... Please for help.

Mark
  • 1,961
  • 4
  • 16
  • 20
  • you need an email server, and xammp doesnt really have a good one installed. So do you have one installed? Also the question probably has been asked and answered before. – kpp Apr 24 '14 at 14:27
  • @kpp sorry, but that is not true, the OP writes that the gmail smtp server is to be used. No need for a local smtp server in that case. – arkascha Apr 24 '14 at 14:31
  • @kpp I've installed something like this: http://glob.com.au/sendmail/ – Mark Apr 24 '14 at 14:32
  • @arkascha well I didnt get it to work on my localhost no matter what I tried but as soon as I dropped my project online on a server(with a mailserver) it worked all fine. – kpp Apr 24 '14 at 14:34
  • @kpp Ah, the good old magically "I did something and things work now". Ok. May I ask what "email server" that was? – arkascha Apr 24 '14 at 14:38
  • I took my project from localhost to the server of the company which I build my project for and they had a personaly modified mailserver installed for the company on the server, so on localhost it didnt work, but when I ported it to the server it did because a mailserver was available. – kpp Apr 24 '14 at 14:42
  • anyhow if the problem is not the mail server then I dont really know what could be the problem here. – kpp Apr 24 '14 at 14:43
  • PHPMailer solved problem. – Mark May 06 '14 at 13:36

1 Answers1

0

Try this,

In php.ini file:

[mail function]

SMTP = localhost

smtp_port = 25

;sendmail_from = yourname@gmail.com

;sendmail_path = "\"D:\xampp\sendmail\sendmail.exe\"-t"

mail.add_x_header = Off

And set the from address in the php code, for example:

$from = "john@example.com";

Also, I don't think you need to change any settings in sendmail.ini file.

Hope this helps.

In addition you can use phpmailer class to send the mail.