46

I want to use the mail() function from my localhost. I have WAMP installed and a Gmail account. I know that the SMTP for Gmail is smtp.gmail.com and the port is 465 (more info from gmail). What I need to configure in WAMP so I can use the mail() function?

Thanks!!

Jonathan
  • 8,676
  • 20
  • 71
  • 101

9 Answers9

28

Gmail servers use SMTP Authentication under SSL or TLS. I think that there is no way to use the mail() function under that circumstances, so you might want to check these alternatives:

They all support SMTP auth under SSL.

You'll need to enable the php_openssl extension in your php.ini.

Additional Resources:

Kubo2
  • 331
  • 3
  • 16
Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
14

I've answered that here: (WAMP/XAMP) send Mail using SMTP localhost (works not only GMAIL, but for others too).

T.Todua
  • 53,146
  • 19
  • 236
  • 237
  • 2
    I need to bookmark this instruction before memory leakage. – Charlesliam Dec 15 '14 at 13:33
  • 1
    Followed those instructions, works perfect with hmailserver 5.6.4 and a gmail account. If you get an error message `530 SMTP authentication is required`, then you need to follow the last indication (the p.s.) – Zimmi Mar 20 '16 at 10:49
11

If you open the php.ini file in wamp, you will find these two lines:

smtp_server
smtp_port

Add the server and port number for your host (you may need to contact them for details)

The following two lines don't exist:

auth_username
auth_password

So you will need to add them to be able to send mail from a server that requires authentication. So an example may be:

smtp_server = mail.example.com
smtp_port = 26
auth_username = example_username@example.com
auth_password = example_password
ArK
  • 20,698
  • 67
  • 109
  • 136
  • 1
    Not tested, but this is probably wrong. There are no such directives for PHP as stated above (except `smtp_port`). Also see http://stackoverflow.com/a/21891895/3827190 as a reference. – Kubo2 Dec 29 '15 at 17:53
3

It's quite simple. (Adapt syntax for your convenience)

public $smtp = array(
    'transport' => 'Smtp',
    'from' => 'your_email@gmail.com',
    'host' => 'ssl://smtp.gmail.com',
    'port' => 465,
    'timeout' => 30,
    'username' => 'your_email@gmail.com',
    'password' => '*****'
)
vinzcelavi
  • 831
  • 9
  • 10
3

As an alternative to PHPMailer, Pear's Mail and others you could use the Zend's library

  $config = array('auth' => 'login',
                   'ssl' => 'ssl',
                   'port'=> 465,
                   'username' => 'XXXX@gmail.com',
                   'password' => 'XXXXXXX');

 $transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
 $mail = new Zend_Mail();
 $mail->setBodyText('This is the text of the mail.');
 $mail->setFrom('XXXX@gmail.com', 'Some Sender');
 $mail->addTo('kazifriend@gmail.com', 'Some Recipient');
 $mail->setSubject('TestSubj');
 $mail->send($transport); 

That is my set up in localhost server and I can able to see incoming mail to my mail box.

Anthony
  • 2,014
  • 2
  • 19
  • 29
kta
  • 19,412
  • 7
  • 65
  • 47
2

use stunnel on your server, to send with gmail. google it.

abel
  • 2,377
  • 9
  • 39
  • 62
2

i know in XAMPP i can configure sendmail.ini to forward local email. need to set

smtp_sever
smtp_port
auth_username
auth_password

this works when using my own server, not gmail so can't say for certain you'd have no problems

Scott Evernden
  • 39,136
  • 15
  • 78
  • 84
1

PEAR: Mail worked for me sending email messages from Gmail. Also, the instructions: How to Send Email from a PHP Script Using SMTP Authentication (Using PEAR::Mail) helped greatly. Thanks, CMS!

bhall
  • 1,391
  • 3
  • 14
  • 19
1

I'm positive it would require SMTP authentication credentials as well.

patricksweeney
  • 3,939
  • 7
  • 41
  • 54