Thursday, April 17, 2014

Send email using Xampp from localhost


I always had problem for testing my PHP codes which were include mail function. I used to upload them on server to test them. But today I decided to find the way to send the mail with PHP using XAMPP from localhost and I found the solution. Then I decided to share this simple tip with you guys. Before we start the procedure you need to have an email address on a running mail server such as Yahoo, Gmail or any other server that you have access to configuration of them as well, because we need their port number.

  1. First go to the path that you installed Xampp application. By default it is "C:\xampp\".
  2. Then we need to find the php.ini file which contains the configurations belong to PHP. This file by default is located at "C:\xampp\php\php.ini". Open it using any text editor like notepad.
  3. Using search in the editor try to find "sendmail_path". There should be two of them. One is commented using a ";" (semicolon) in the beginning of the line , and the other one is not commented. Comment the one that is active and active the one is commented. After the edit it should looks like below... (Similar)
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
    ; XAMPP: Comment out this if you want to work with mailToDisk,...
    ;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
  4. Save the php.ini file and restart the Apache process. This is necessary for the configuration to take place.
  5. Next navigate to the sendmail directory. By default it should be located at "C:\xampp\sendmail" and open the "sendmail.ini" in the text editor.
  6. Now we need to set the configuration for the mail server. For this case I chose Gmail. The SMTP address of Gmail is: "smtp.gmail.com" and the SMTP port for Gmail is "587".
  7. Find "smtp_server" and write the Gmail SMTP address in front of that.
  8. Find "smtp_port" and write the Gmail SMTP port in front of that.
  9. Scroll down , you should be able to see "auth_username" & "auth_password". Put your gmail username in front of  auth_username and put the password in front of auth_password .
  10. Save and now you are good to send mail from local host. 
  • Note that your PHP mail function should have "from" header,otherwise your mail will not go through. 
  • Also remember the that the destination will receive the mail from your Gmail address not from the address you put in your PHP code.
  • The following code is a simple example of PHP script which can send a successful mail.
<?php
$to = "destinationAddress@Anywhere.com";
$subject = "The mail subject goes here";
$content= "And this is the mail content!";
$headers = "From:Me@Mywebsite.Com\r\n";

mail($to,$subject,$content,$headers);
?>

THIS MAY NOT WORK ON SOME OF WINDOWS 8 OR 8.1 DUE TO THE SECURITY LIMITATION.
Please make sure your firewall, antivirus or other security software is not stopping the sendmail.exe to communicate with internet!

10 comments:

  1. This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. instant instagram likes uk

    ReplyDelete
  2. Efficiently written information. It will be profitable to anybody who utilizes it, counting me. Keep up the good work. For certain I will review out more posts day in and day out. https://hotmail.inf.br/

    ReplyDelete
  3. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! hotmail

    ReplyDelete
  4. As consistently the great and the evil resemble different sides of a coin. In spite of the fact that the focal points exceed the detriments it's about time that we investigated them before they spread.cyber security in hyderabad

    ReplyDelete
  5. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. hotmail entrar

    ReplyDelete
  6. Many users of this new manner of faxing will gladly factor out other advantages of on line faxing.fax documents online encryption

    ReplyDelete
  7. Sophisticated surveillance cameras are common place in premise security but 24 response app there is still a need for "human eyes" and many businesses do not have any real alternative to footing the bill for security guards.

    ReplyDelete
  8. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. how to send fax from phone

    ReplyDelete
  9. If you've ever gone to a website and were asked for your email address in exchange for a free product or download, then you've seen this in action.best email extractor software review

    ReplyDelete
  10. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this..........send fax from email
    send fax from email

    ReplyDelete

Social Networks Sharing