0

My PHP code for sending mail is:

$email_to="deepuskmr@gmail.com";
$email_subject="It works";
$email_message="Hello. I can send mail!";
$headers = "From:Dpu\r\n".
"Reply-To: sdeepu.kmr@gmail.com\r\n'" .
"X-Mailer: PHP/" . phpversion();
mail($email_to, $email_subject, $email_message, $headers);  
echo "mail sent!"

But this code not sending email. It gives the error. enter image description here

My php.ini file settings are

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = sdeepu.kmr@gmail.com

I am working in localhost. And I am using windows 64 machine.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97

3 Answers3

0

You are using localhost as mail server, if you did not installed one (SMTP server), this will obviously returns you cannot connect.

You should have something like :

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 587
Alexis Paques
  • 1,885
  • 15
  • 29
0

I use the free and awesome hMail on my dev box so that I can test my email functions and not just get mail() errors!

http://www.stylus.co.za/setting-up-hmail-on-your-development-box/

foxbeefly
  • 510
  • 3
  • 13
0

I have hosted site on Fasthost, it is a windows server.we can’t send emails by using any arbitrary address as ‘From’ address in Fasthosts platform due to security reasons, The “from” address must be a mailbox that exists on the Fasthosts platform.