Hello readers, Today in this blog you'll learn how to send Mail from Localhost XAMPP using PHP. Simply, XAMPP is an abbreviation for cross-platform, Apache, MySQL, PHP, and Perl. XAMPP lets you work on a local server and test local copies of websites using PHP code and MySQL databases.
To send mail from localhost XAMPP using Gmail, configure XAMPP after installing it. To configure the XAMPP server to send mail from the localhost, we have to make some changes in two files one is php and another one is sendmail.ini.
First, go to the XAMPP installation directory and open the XAMPP folder and follow the below steps same:
1. Go to the (C:\xampp\php) and open the php file then find the mail function by scrolling down or simply press ctrl+f to search it directly then find the following lines and pass these values. Remember, there may be a semicolon ; at the starting of each line, simply remove the semicolon from each line which is given below.
PHP FILE:
That's all for this file, save the file by pressing ctrl+s and close it.
2. Now, go the (C:\xampp\sendmail) and open the sendmail.ini then find sendmail by scrolling down or press ctrl+f to search it directly then find the following lines and pass these values. Remember, there may be a semicolon ; at the starting of each line, simply remove the semicolon from each line which is given below.
SENDMAIL.INI FILE:
That's all for this file, save the file by pressing ctrl+s and close it. After all changes in the two files, don't forget to restart your apache server.
Now, you're done with the required changes in these files. To send mail using Gmail paste the following codes in your PHP file.
PHP CODE:
- Go to your Google account then click on the Security tab and scroll down, there you can see the Less secure app access panel, Simply turn on that. This panel only shows if you haven't enabled 2-Step Verification. alert-info
If you're getting an error as a password is wrong then simply go to the sendmail.ini file and put the correct password of your Gmail account which you've provided in sendmail_from in sendmail.ini.

Great 👌😍
ReplyDeleteThank you :)
DeleteThanks for this, now if we are using another server online,(after publishing our website online),will the mail sending still work?
ReplyDeleteyes
DeleteThanks for this, now if we are using another server online, (after uploading our codes online), will the mail sending still work?
ReplyDeleteNo you've configure require changes in your server file. This is only works on XAMPP server.
Deletecan u make something like this again but with rust instead of php. Rust is faster and synatically equal to c++.
ReplyDeleteSadly.. I haven't knowledge of c++
DeleteBro please make a video in it.
ReplyDeleteOk bro
Deletewhich php file should i copy and paste the last code ?, i got an error that says failed while sending code
ReplyDeleteYou've to create a PHP file with the extension .php and paste the last codes on that PHP file but before pasting the codes make sure you've configured the XAMPP and turn on less secure app on your google account. You can read this blog carefully.
Deletehy
ReplyDeleteWarning: 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\usertable\controllerUserData.php on line 33
ReplyDeleteI KEEP GETTING THIS
You haven't configured your XAMPP properly...Please read this blog carefully and apply the changes in your files.
Deletedid you find the solution on this error? need help...
DeleteWarning: 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\usertable\controllerUserData.php on line 33
ReplyDeletewhat does it mean
Please recheck your changes files with the above given codes.
DeleteI followed all the steps but an error message appeared to me saying
ReplyDeleteWarning: 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 \ p1 \ mail.php on line 7
Sorry, failed while sending mail
Please recheck your changes in files.
DeleteHola buenas tardes, me manda el siguiente error:
ReplyDeleteAdvertencia:mail(): No se pudo conectar al servidor de correo en el puerto 25 "localhost", verifique su configuración "SMTP" y "smtp_port" en php.ini o utilice ini_set() en C:-xampp-htdocs-Verificacion de email-controllerUserData.php en la línea 33
English please!
Deletesir, i configured properly...... but when i try to signup .... it redirect me to otp verification page.... no email comes to the gmail... please help me...
ReplyDeleteMaybe the email address you've entered doesn't exist or You may haven't on Less Secure Apps panel in your google account
Delete
ReplyDeleteWarning: 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\swda\controllerUserData.php on line 33
please help sir
Please configure carefully. Maybe you did some mistakes.
Delete<?php
ReplyDelete$receiver = "receiver_email@gmail.com";
$subject = "Email Test via PHP using Localhost";
$body = "Hi, there...This is a test email send from Localhost.";
$sender = "From:sender_email@gmail.com";
if(mail($receiver, $subject, $body, $sender)){
echo "Email sent successfully to $receiver";
}else{
echo "Sorry, failed while sending mail!";
}
This php file with what name we have to save and where it showing error
Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 78sm5550625pfz.211 - gsmtp in C:\xampp\htdocs\Login and Signup Form with Email Verification - PHP\controllerUserData.php on line 33 (Failed while sending code) I configure all xampp and sendmail settings.
Create a php file inside the HTDOCS folder with .php extension and paste the following codes in this file then put the receiver email and sender email address in the mentioned fields.
Delete
ReplyDeleteWarning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. x5sm10407906pfr.83 - gsmtp in C:\xampp\htdocs\Login and Signup Form with Email Verification - PHP\controllerUserData.php on line 33
Great 😊 thanks you
ReplyDeleteFor help 👍
You're welcome :)
Deletebro please make a video for it i am confused
ReplyDeleteSure stay tuned with us.
DeleteWhen run the php file result is email sending failed
ReplyDeleteDid you enbale less secure app panel on your google account?
DeleteSir I configured properly but result is email sending failed.pls help
ReplyDeleteDid you enable less secure app panel on your google account?
DeleteWhen will you be making this video, I really need help on this for my school project?
ReplyDeleteCan you send me the screenshot of your problems on my Instagram account?
DeleteNo error in the code, but mail is not sending
ReplyDeleteNo error while PHP codes runs ,and it turn to OTP page.but mail didn't send to corresponding ?.pls help me out
ReplyDeleteSir, when will you make a tutorial about the login and sign up with email otp verification??? huhu
ReplyDeleteafter registration i keep getting error of failed while sending code even after enabling less secure apps what should i do
ReplyDeletefor all of u that have "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\swda\controllerUserData.php on line 33 error pls restart your apache.
ReplyDeleteNice one! That worked!
DeleteWarning: 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:\wamp64\www\login\controllerUserData.php on line 118
ReplyDeletewhat was the mistake?
how do I get a specific password from google?? the error log keeps giving me this msg Application-specific password required. failed while sending email
ReplyDeleteHi thanks for this tutorial and instructions but I got the error warning after I signed up.
ReplyDeleteThe data is already input on my data base. Name, email, password and the code also the verification
But the email is not.
Warning said is mail():SMTP server response 530 5.7.0 must issue a starTTLS command first.gjlsm12559445pjb.11 - gsmtp in "distinction folder" on line 33 where located this code-->> if(mail($email, $subject, $message, $sender)){ . . . . ..
Please read the blog carefully...I can't do anything except this...All answers are in the blog.
Deletehi? did you find any solution for this? It is the same error I'm facing rn help plsss
Deletesorry to disturb admin. I have followed the instructions for creating your website and I entered the registration menu. I have filled in all the data then I press the register button. a text appears. FAILED WHEN ENTERING DATA TO DATABASE ??
ReplyDeletePlease explain where I went wrong. Thank you
sorry to disturb admin. I have followed the instructions for creating your website and I entered the registration menu. I have filled in all the data then I press the register button. a text appears. FAILED WHEN ENTERING DATA TO DATABASE ??
ReplyDeletePlease explain where I went wrong. Thank you
sorry to disturb admin. I have followed the instructions for creating your website and I entered the registration menu. I have filled in all the data then I press the register button. a text appears. FAILED WHEN ENTERING DATA TO DATABASE ??
ReplyDeletePlease explain where I went wrong. Thank you
This blog is about configuring XAMPP...I think you're facing the error which is not related to this blog. So please read this carefully - https://www.codingnepalweb.com/2020/09/login-signup-form-with-email-verification-php-mysql-bootstrap.html and must be careful while putting the name of database, table, and columns.
DeleteLogin-singup-form-with-email-verification using phpmailer can you make this video
ReplyDeleteOk stay tuned
DeleteThanks for the tutorial. I got this error:
ReplyDelete21/01/20 11:13:23 : Username and Password not accepted. Learn more at https://support.google.com/mail/?p=BadCredentials f13sm1134675iog.18 - gsmtp
To fix this problem, I had to login to my Gmail account, go to security, and then turn on "Less secure app access." This is "not recommended" according to Google, but it wouldn't work without this setting turned on.
Yes you're right
DeleteWarning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\email\controllerUserData.php on line 19
ReplyDeletewhats happen??
Warning: mail(): Failed to connect to mailserver at "smtp.gmail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\SIS\contact.php on line 41
ReplyDeleteits been 2hrs since ive been trying to read the blog
pleasseeee helpppp
i already got it after 3h THANKK YOU.
ReplyDeletefor errors , kindly restart your apache after encoding those codes.
and some are in comment in php.ini so we should remove the " ; " to enable the lines
after that dont forget to enable the less app in gmail settings
Great now you can send Email to any existing email address from localhost
DeletePlease why do I receive an error message say "Access denied"while saving the PHP.ini file
ReplyDeleteMaybe you don't have permission to change the C drive files
DeleteAlso there's PHP.in-production and PHP.ini-development
ReplyDeleteThe above one is. There is a name with php before php.ini-development. You've to open it
DeleteI keep getting this error. Please help. I have configured properly as mentioned abovee
ReplyDeleteWarning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Jai tombé sur cet erreur là: "Failed while sending code!"
ReplyDeleteIt would have been better if there was a video to help beginners like me
ReplyDeleteYes I think it definitely help to all beginners.
DeleteThanks worked .. I was getting multiple issues ..as I open the .ini files in notepad... If you can update the comment .. the ini.. to be opened in PHP ... most error will be sorted.
ReplyDeleteOk I'll update it soon. When I posted this blog, there is php.ini file for configuration but now it's only php.
Deleteauth_username=your_email_address_here
ReplyDeleteauth_password=your_password_here
in this we have to pass email address and password or paste it like this only
not able to find mail function in php
ReplyDeletePLEASE MAKE A VIDEO ON IT
ReplyDeleteits not working please make it on javascript smtp.js
ReplyDeletei watched your other tutorial and i have a question sir?
ReplyDeleteshould i enter the last part of the code PHP CODE: to my controllerUserData.php or separate file?
Heyy the last php code
ReplyDeleteSo be with which name just .php or like some name send.php???
PLZZ helpp
1.when i click on the send mail it shows this page is not working can you please help?
ReplyDelete2.we need to link our php file to index.html or not?
Hi, how can I config wampp server for send mail
ReplyDeleteI didn't recieve the email, and yes, I turn on the "less secure apps" on Google. The blog was great but I think you should update it, so that you can address the multiple problems we are all having.
ReplyDeleteHello sir how to use on infinity hosting or any website i upload this login page but not working
ReplyDelete$receiver = "receiver email address here";
ReplyDelete$subject = "Email Test via PHP using Localhost";
$body = "Hi, there...This is a test email send from Localhost.";
$sender = "From:sender email address here";
if(mail($receiver, $subject, $body, $sender)){
echo "Email sent successfully to $receiver";
}else{
echo "Sorry, failed while sending mail!";
}
where want to paste this code. pls
hello sir how to configure login and signup in cpanel
ReplyDeleteThanks for doing tutorials. What to do if I'm using macbook?
ReplyDeletePost a Comment
We welcome relevant and respectful comments. Off-topic or spam comments may be removed.