0

How to send email from wamp/xampp localhost? I have written the following simple code to send message.

I have already edited php.ini,sendmail.ini configuration files but no use,I can't receive email.I want to send message to any gmail address.I can sent email to my domain mail when this piece of code is uploaded via filezilla to my domain, but when I am giving to address as any gmail id, the code is not working.

<?php
    $to = "bytecookiestest@gmail.com";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: swetha851991@gmail.com";
    $s=mail($to,$subject,$txt,$headers);
    if($s)
        echo "success";
    else
        echo "failure";
?>
Sivaprakash
  • 455
  • 1
  • 8
  • 22
SwR
  • 612
  • 1
  • 8
  • 21

1 Answers1

3

It's most likely a problem with the from-header you're sending. You're using your own Gmail-address to send mails from, but that also means you have to use the Google SMTP server. The credentials of swetha851991@gmail.com are the credentials you have to use to authenticate with the SMTP server. It'll otherwise be marked as spam.

Another option is to set the from-address to an address from the domain you're sending it from. If you domain is example.com, you can set the from-address to anything@example.com.

Sherlock
  • 7,525
  • 6
  • 38
  • 79
  • But I didnt give swetha851991@gmail.com as to address.So I hope there is no problem with my headers,please make it clear for me. – SwR Mar 23 '15 at 12:41
  • It doesn't matter where you send it `to`, it matters where you send it `from`. Spam servers bounce e-mails with invalid headers. i.e. a Gmail-address from a different server than Google's. – Sherlock Mar 23 '15 at 12:47