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.

35 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
    Replies
    1. Email successfully sent to javalight86@gmail.com...
      successfully ka message ata he but mail send nahi hota?

      Delete
    2. send path mein -t se pehle space hai "\"C:\xampp\sendmail\sendmail.exe\" -t"

      Delete
  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
  7. After the changing the less secure apps, still the webpage says that email send successfully but the actual mail is not received on the destination.

    ReplyDelete
  8. Email send ho raha hai local host pe par receiver pe nhi aa raha hai sir please iska solution batado

    ReplyDelete
  9. Sir Email send nhi ho rahi error da raha hai.

    ReplyDelete
  10. Hello sir
    email send successfully but the actual mail is not received

    ReplyDelete
  11. Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\sending_mail\mail.php on line 7
    Email sending failed...

    ReplyDelete
    Replies
    1. same here ..if you have done please tell me

      Delete
  12. mere xampp pe php.ini file nhi hai...please reply

    ReplyDelete
  13. Hotmail login Most of us had heard the name of Hotmail. First free email service in the early years of the 2000s. I am sure many of you had an account there too. Today we will talk about Hotmail and also will discuss how we can use the new version of this email service in 2020.

    ReplyDelete
  14. Hey, for me, it is showing mail not sent. Plz help

    ReplyDelete
  15. Email is sent but I did not receive it

    ReplyDelete
  16. Dear sir,
    Mail is successfully send display in php but it is not received in gmail.

    ReplyDelete
  17. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. m2sm12856062pjf.34 - gsmtp in C:\xamppServer\htdocs\WEBPRACTICE\form14\mail.php on line 7
    Email sending failed...
    not connected suggest some help

    ReplyDelete
  18. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. h20sm3546230pfo.105 - gsmtp in F:\xampp\htdocs\ajax\mail.php on line 9
    Email sending failed...
    can you please help me sir...

    ReplyDelete
  19. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… hotmail login account

    ReplyDelete
  20. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. hotmail email

    ReplyDelete
  21. hi,
    i am unable to send smail .i have followed your videos but unable to send email for recover password. no error but email sending is fail . can you reply me . its urgent . i have tried phpmailer too that too not working

    ReplyDelete
  22. I am getting this error:
    Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. l63sm3060395pfd.122 - gsmtp in C:\xampp\htdocs\registrationFormWithMail\index.php on line 53

    ReplyDelete

  23. E-mail is successfully send display in php but it is not received in gmail.

    ReplyDelete
  24. Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\search\index.php on line 8
    Email sending failed...

    ReplyDelete