This may seem a little obscure but believe me, this blog could save you a lot of time.
Imagine you have XAMPP installed on your Windows computer as localhost. You are writing an application which requires e-mails to be sent and you need to test your code. You have a Google e-mail account and you'd like to use the SMTP service which comes with that.
Let's start by creating our little PHP script which we are going to use for testing.
<?php
mail('jimmy@googlemail.com','test subject','test body');
?>
There. That wasn't too difficult was it.
Next we need to edit our php.ini file. The php.ini file will be in something like C:\XAMPP\php. We are looking for the [mail function] variables. For which we need entries like this:
[mail function]
sendmail_path = "C:/xampp/sendmail/sendmail.exe -t"
Couple things to note from above. The smtp_port and look carefully at the slashes of the sendmail_path.
Now we are on to our final step. We need to edit sendmail.php which would be under something like C:\XAMPP\sendmail. You need to replace the contents of the file with something like this:
[sendmail]
smtp_server=smtp.googlemail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=myaccountname@googlemail.com
auth_password=mypassword
force_sender=myaccountname@googlemail.com
You must now restart your Apache service in order for it to work.
Now to test your script. Open up your web browser and load it like this http://localhost/myscript.php
Check your Google mail account to see if it's arrived.
Good luck!
No comments:
Post a Comment