THAPA TECHNICAL

HOUSE OF WEB DEVELOPERS AND TECHNOLOGY.

How to send mail from localhost XAMPP using PHP

How to send mail from localhost XAMPP using PHP


To send mail from localhost XAMPP using Gmail, configure XAMPP after installing it. Follow the below steps for the same.

Steps to Send Mail From Localhost XAMPP Using Gmail:

Open XAMPP Installation Directory.


Go to C:\xampp\php and open the php.ini file.
Find [mail function] by pressing ctrl + f.
Search and pass the following values:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = YourGmailId@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"


Now, go to C:\xampp\sendmail and open the sendmail.ini file.

Find [sendmail] by pressing ctrl + f.
Search and pass the following values
smtp_server=smtp.gmail.com
smtp_port=587 or 25 //use any of them
error_logfile=error.log
debug_logfile=debug.log
auth_username=YourGmailId@gmail.com
auth_password=Your-Gmail-Password
force_sender=YourGmailId@gmail.com(optional)

Here is the actual code that you have to write
Script To Send Mail:

<?php
$to_email = "receipient@gmail.com";
$subject = "Simple Email Test via PHP";
$body = "Hi, This is test email send by PHP Script";
$headers = "From: sender email";

if (mail($to_email, $subject, $body, $headers)) {
    echo "Email successfully sent to $to_email...";
} else {
    echo "Email sending failed...";
}



**Note: If you are getting a warning message then Please configure “Less secure apps” settings as shown below. Sometimes without turning on the 'less secure apps' is the main reason the user didn't receive the mail.

=> Turning on 'less secure apps' settings as mailbox user

Go to your (Google Account).
On the left navigation panel, click Security.
On the bottom of the page, in the Less secure app access panel, click Turn on access.
If you don't see this setting, your administrator might have turned off less secure app account access (check the instruction above).
Click the Save button.

** Now your email will be sent successfully. Have a good day and please share your story in the comment box.

7 comments:

  1. helo bhai user aur admin panal ki vidio banawo app ki sari vidio dekhat hu lekin app abhi tak admin panell par vidio nahi banaye

    ReplyDelete
  2. hello sir mere xamp server pe php.ini sho nahi kar raha hai please reply

    ReplyDelete
  3. Email send ho raha hai local host pe par receiver pe nhi aa raha hai

    ReplyDelete
  4. hi,
    please make a video with multiple email attachement

    ReplyDelete
  5. sir as a shop ak website please a video

    ReplyDelete
  6. Wamp server pe nhi hai sendemail

    ReplyDelete