9

I've seen a lot of videos but haven't got a hang of how to send mail in php.

I've configured the smtp port and server along with php.ini file and also the sendmail.ini file, changed the auth_username and password. However, the code below still does not work!

<?php
    mail('xyz@gmail.com','Hello','Testing Testing','From:abc@gmail.com');
?>

Do I need to download anything or change the gmail settings?

Leigh
  • 28,765
  • 10
  • 55
  • 103
user2280276
  • 125
  • 1
  • 2
  • 7
  • Are you trying to send mails from `localhost`? – Mr. Alien Apr 14 '13 at 19:02
  • yaa i'm using xampp!but i need the msgs to b sent from my gmail account.i have a internet connection on @Mr.Alien – user2280276 Apr 14 '13 at 19:07
  • see this tutorials http://digiex.net/guides-reviews/guides-tutorials/application-guides/544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl.html – mohammad mohsenipur Apr 14 '13 at 19:08
  • You should really use a proven solution like PHPMailer for this because there are dozens of potential pitfalls you might encounter if you try to do it yourself. Take a look at http://phpmailer.worxware.com/index.php?pg=examplebgmail –  Apr 14 '13 at 19:14
  • Ghe guys here can explain more, but I have more of a linux experience when it comes to mail, but do not attempt to configure a mailserver without the correct knowledge, because if you miss out one thing, you could fail the,security checks and your outgoing mail would end up in the spam. Use other PHP solutions,which has this configured for you such as PHPmailer – Daryl Gill Apr 14 '13 at 19:24

1 Answers1

9

It's very easy to configure php.ini for sending e-mails from your server.You just need to configure php.ini and sendmail.ini correctly.

First you have to configure sendmail_path in your php.ini file it should have to point to executable sendmail file with proper flags

for example , ;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" (which is already in your php.ini file need to just remove comment) and other assignments to sendmail_path need to be commented.

after configuring php.ini file you need to configure sendmail.ini file ,in that

first smtp_server=mail.gmail.com (as you want to use gmail as smtp server), second smtp_port=465 (if not worked try 587), third auth_username= yourid@gmail.com auth_password=yourpassword

after this restart your server.

Harshavardhan
  • 1,266
  • 2
  • 14
  • 25
  • this is working. maybe you can try to set `smtp_ssl=ssl` if `smtp_ssl=auto` didn't work. but i need to instal apache and mysql then restart. not just running from xampp control panel. i don't know why. – Hammond22 Sep 05 '13 at 16:45
  • I have been faffing around with Mercury and this is the solution I needed. Wish I found this yesterday – bubblebath Sep 25 '13 at 09:39