-3

I need to send mail from PHP code, I am using XAMPP (windows) for PHP. I use mail() like this:

Here is my code in php.ini:

[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 =email@gmail.com

My PHP code:

if(mail("email@gmail.com",$subject,$message))
{
  echo "mail sent";
}
else
{
  echo "error";
}

I get the message 'mail sent' but did not receive an email. What am I doing wrong?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
user2247744
  • 125
  • 1
  • 5
  • 12
  • possible duplicate of [Sending email from localhost in php in windows](http://stackoverflow.com/questions/10044478/sending-email-from-localhost-in-php-in-windows) – putvande Feb 27 '14 at 12:17
  • 1
    I am certain there are at least a dozen questions of the exact same ilk. A search would help. But as for gettting "mail sent", have a look at the return value section at http://us2.php.net/manual/en/function.mail.php: "It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination." – Brian Warshaw Feb 27 '14 at 12:18
  • do you have an SMTP server on your localhost? did you try using different SMTP settings? Try gmail settings, you will be able to narrow down the issue to check either mail server or your code. – Fr0zenFyr Feb 27 '14 at 12:19
  • I have used ini_set for smtp from php code and i am getting the error as The host name specified in HELO does not match IP address.Please guide me – user2247744 Feb 28 '14 at 04:56

3 Answers3

0

You are using gmail to send email then you should configure gmail POP settings... In general you need to have SMTP Server configured on server.

Rohit Awasthi
  • 686
  • 3
  • 12
  • But i have a form which contains sender and recipient textbox where different users can send email.So the from email may change.I cant tell its should gmail.com – user2247744 Feb 27 '14 at 12:22
  • Gmail POP settings has nothing to do with your 'from' email. – Fr0zenFyr Feb 27 '14 at 12:23
0

You've set up this smtp server: "localhost:25". Do you have some SMTP-server running on this port on your local machine?

If you want to send emails from local machine you should either setup some SMTP-server locally (but this is not simple) or use some remote SMTP-gateway. Google for it.

Upd. Anyway this is duplicate How to configure XAMPP to send mail from localhost?

Community
  • 1
  • 1
Stalinko
  • 3,319
  • 28
  • 31
0

Use smtp.gmail.com as smtp host and set port to 587, you will also need to set up authentication and for that reason I'd suggest using something a bit more advanced than the native mail function; examples are PEAR's Mail package, SwiftMailer or PHPMailer.

kguest
  • 3,804
  • 3
  • 29
  • 31