I have been trying to send email using PHP script and XAMPP Lite. The PHP script itself is not a biggies but the default XAMPP configuration doesn’t allow me to send out the email. My objective is to use Gmail as my SMTP (rather than localhost). After some digging and try and error.. here is my solution.
- Edit your php.ini (xampp\php\php.ini). Search for [mail function] and change these parameters accordingly.
- SMTP = smtp.gmail.com
- smtp_port = 587
- sendmail_from = [your_gmail_username]@gmail.com
- Note: this gmail account will be used to send the email
- sendmail_path = “\”D:\xampp\sendmail\sendmail.exe\” -t”
- Note: I did install my xampp at D:\xampp
- Edit your sendmail.ini (xampp\sendmail\sendmail.ini)
- Comment the “Mercury” and “A free mail service example” contents as shown below:
# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off
# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#host smtp.live.com
#from [exampleuser]@hotmail.com
#auth on
#user [exampleuser]@hotmail.com
#password [examplepassword]
2. Add the account through which you want to send your mails. In my example I have configured the Gmail account as shown below:
account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from [your_gmail_username]@gmail.com
auth on
user [your_gmail_username]@gmail.com
password [your_gmail_password]
port 587
3. Set the default account to Gmail as shown below:
account default : Gmail
Many thanks to Pallavi. His original post point me to the right direction. The only missing piece is port number in sendmail.ini where gmail no longer use port 25 as smtp port but 587. Hope this help.
Dude it worked, thanks a lot!
soooory didn’t working,pls help me,for the better one.
not woeking for me two
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in E:\xampp\htdocs\email\index.php on line 20
Message delivery failed…
It didn’t work. Can you be more clear. let me know the Xampp version and URL link if possible thank you
[…] https://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/ […]
<?php
I HAVE DINE WHAT YOU SAY ABOVE(CHANGES IN PHP.INI AND SENDMAIL.INI)CODE SUCCESSFULLY RUNS BUT E-MAIL NO DILIVERED.THIS IS MY CODE FOR MAIL
$to = "dinesh.sawlani@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("Message successfully sent!”);
} else {
echo(“Message delivery failed…”);
}
?>
Worked perfectly – thanks
[…] https://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/ […]
have been searching the right methods for ages!.
this work prefectly great thx!
Thank U So Much I Am Searching for this help for one day it work perfect thanks a lot!!!
After a server restart worked like a charm!
Thank you
Thank you so much men. I’ve burned a lot of time searching
for the right answer, finally I got this.
for ($i = 1; $i <= infinity; $i ++)
echo "THUMBS UP";
This was exactly what I was looking for!! You are my hero.
Glad it help many of us 😀
wow i`m searching for this tutorial all day 😉 works great but very slow , do You have this some problem?
Hello guys, this script has been a great help, however, I still can’t seem to send any emails, the script validation tells me the email was sent, but none ever arrived. Hope you can help me.
Dude.. I had been looking for this all day! Thanks a ton!
not working please provide me some help
We have to keep the gmail account logging and active through browser on the machine where apache works at the moment when we try to send mail
Thank you very much ! Yes indeed this works. Very very happy =)
Thank you so much.
It’s working now. But emails sent from ‘user [your_gmail_username]@gmail.com’ not from ‘from[your_gmail_username]@gmail.com’.
Btw, how to configuration an CC, Bcc in this sendmail.ini?
Great stuff, used this to help some other people. Thanks for it.
why does my sendmail.ini look so different?
; configuration for fake sendmail
; if this file doesn’t exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS’s pickup directory cause sendmail to
; run quicker, but you won’t get error messages back to the calling
; application.
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=587
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn’t provided
; if you want to override the value in the registry, uncomment and modify
default_domain=gmail.com
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
;error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
;auth_username=ellibs07@gmail.com
;auth_password=
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the “MAIL FROM”
; command, it won’t modify the “From: ” header of the message content
;force_sender=me@localhost
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
;hostname=localhost
What is wrong here?
same problem here…..
did you guys find a solution to this? i have the same sendmail file.
are you using xampp LITE?
ha nvm i feel stupid!
I am having the same problem … How can I overcome this ?
Thanks a lot! That works great.
[…] Thanks to Selim vai for sharing this, original post : […]
You’re a legend – I’ve wasted about 7 hours going through loads of different combinations with smtp server etc. However, with this set up this will work everywhere no matter which ISP I use.
I made all the changes however the mail is not delivered inspite of a successfl msg..cn ne1 help?
thanks
my sendmail.ini is same as Elery.need help plzz
; configuration for fake sendmail
; if this file doesn’t exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS’s pickup directory cause sendmail to
; run quicker, but you won’t get error messages back to the calling
; application.
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=587
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn’t provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=local
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
;error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
auth_username=luvbeggrz@gmail.com
auth_password=
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the “MAIL FROM”
; command, it won’t modify the “From: ” header of the message content
;force_sender=me@localhost
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
;hostname=localhost
mine is also same… any idea guys 😦
Guyz please mail me the entire procedure..
I didn’t get it..
please mail me at srihari2k8@gmail.com..
I’m using XAMPP 1.7.4
yeah it works for meee !!!!!!!!!!!!
for people who didn’t get this tutorial,
CHECK IN THE PHP.ini
;sendmail_from:
remove the “;” at the beginning
so it’s :
sendmail_from:
THE SAME THING FOR THE sendmail_path:
=) enjoy
Hello, no doubt, this is a very nice site containing nice articles. But I tried to send Email using Gmail in the php.ini, but couldn’t send email.
hi, i have the same problem with hasnat,
ive been digging through different articles in the net but still unlucky to solve my problem.
Can anyone send me the working sendmail.ini file? my gmail is johncode.reymaster@gmail.com
Ill appreciate further help… thnx alot
allow me to translate to Indonesian, there might people need this article in indonesian
Dipersilakan dan dialu-alukan.
Can anyone plz send me sendmail.ini file? I am getting the output ..
My email id is ” akshaya.patil108@gmail.com“
Sorry i am not getting d output
im having this error…
Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for [email_address]@yahoo.com in C:\xampp\htdocs\LAUS\sendmymail.php on line 9
Message delivery failed…
help me fix this please…
thanks, it work great……….
Thank you very much Author, this is very useful technique to testing script on localhost… 🙂
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. h9sm55880116pbq.14 in
I had this error. What to do? 😦
I got this error when i send mail using gmail smtp server
authentication failure [SMTP: Invalid response code received from server (code: 535, response: 5.7.1 Please log in with your web browser and then try again. Learn more at 5.7.1 https://support.google.com/mail/bin/answer.py?answer=78754 s8sm8854125wiz.8)]
Here is my code
$from,
‘To’ => $to,
‘Subject’ => $subject);
$smtp = Mail::factory(‘smtp’,
array (‘host’ => $host,
‘port’ => $port,
‘auth’ => true,
‘username’ => $username,
‘password’ => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo(“” . $mail->getMessage() . “”);
} else {
echo(“Message successfully sent!”);
}
?>
please help me
I AM sending mail to gmail from XAMPP. but i am getting message sent.. but messages are not delivered,,, pls help me…
Am also getting samething….help me any one
Hi,
I would just like to share this PHP mail script I found it works 🙂 I’ve added a form so it’s just a copy and paste to your server
Email sending LaquiMe
From:
laquitrooper@gmail.com
Send To:
Subject:
Body/Content:
It worked for me on my xampp and joomla 2.5 setup.
I have been searching for a solution since a long.
Thanks a lot.
Ganesh
[…] (it has a limit so it's not useful for production) so there are a lot of guides out there like this one that discuss how to set it up. Originally Posted by bryan19 this is the error sir..?? […]
[…] https://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/ […]
Hi,
my sendmail.ini file looks like below,
; configuration for fake sendmail
; if this file doesn’t exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS’s pickup directory cause sendmail to
; run quicker, but you won’t get error messages back to the calling
; application.
smtp_server=localhost
; smtp port (normally 25)
smtp_port=25
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn’t provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=local
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
;error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
;auth_username=
;auth_password=
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the “MAIL FROM”
; command, it won’t modify the “From: ” header of the message content
;force_sender=me@localhost
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
;hostname=localhost
any idea pls revert back
Thank you,
I had the same problem.
I founded the anwser here : http://stackoverflow.com/questions/4948687/xampp-sendmail-using-gmail-account
it’s not showing any error but the mail is not send!!!
Thankyou! worked perfectly.
Maybe you want to put a short example to check if it works:
if( mail(‘to_this_mail@gmail.com’, ‘Subject’, “Message”, ‘From: user@example.org‘) ){
echo “Sended!”;
}
Thanks a lot 🙂
its working..!!!
wow, it’s working, thanks man, but i must restart my xampp before, and it’s great thanks 😀
thank you dude, its working.
wow… its working now…
not working for me i have add this in php code
<?php
$to = "test@yahoo.com";
$subject = "Hi!";
$message = "Hi,\n\nHow are you?";
$headers = 'From:test.test@gmail.com' . "\r\n"; //
and enable this to sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log// find out what error
auth_username=test.test@gmail.com
auth_password=testtest
and it work!
sorry the code was cut
add this $headers = ‘From:test.test@gmail.com’ . “\r\n”;
and call this
if (mail($to, $subject, $message, $headers)) {
echo(“Message successfully sent!”);
} else {
echo(“Message delivery failed…”);
}
THANX IT WORKS … Great job
hey buddy, plz send me your php.ini file content on my email vivekkumarsingh71@gmail.com
Not working, Kindly anyone upload the working php.ini file here.
really thanks.. its work.. many thanks for u..
you took away a bit of my stress because di fuckin mail.. thanks again..
mail inbox-e jai na
i have the same sendmail.ini like “Aravind”, I did all the setup. It send the message, but doesn’t received by the reciever
Try SMTP4PHP also! 🙂
https://plus.google.com/109110210502120742267/about#109110210502120742267/about
THANX IT WORKS … Great job
plzzzzzzzzzzzzzzzzz plzzzzzzzzzzzzzzzzzz help me
i can not configure my xampp send mail file help me plzzzzzzzzzzzzz
; configuration for fake sendmail
; if this file doesn’t exist, sendmail.exe will look for the settings in
; the registry, under HKLM\Software\Sendmail
[sendmail]
; you must change mail.mydomain.com to your smtp server,
; or to IIS’s “pickup” directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS’s pickup directory cause sendmail to
; run quicker, but you won’t get error messages back to the calling
; application.
smtp_server=localhost
; smtp port (normally 25)
smtp_port=25
; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn’t provided
; if you want to override the value in the registry, uncomment and modify
;default_domain=local
; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging
;error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
;
auth_username=matifniaz90@gmail.com
;
auth_password=******
; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines
;pop3_server=
;pop3_username=
;pop3_password=
; to force the sender to always be the following email address, uncomment and
; populate with a valid email address. this will only affect the “MAIL FROM”
; command, it won’t modify the “From: ” header of the message content
;force_sender=me@localhost
; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required
;hostname=localhost
For those of you with the different type of ‘sendmail.ini’, make a backup copy of the sendmai.ini file, then replace the entire file with this:
;;; START SENDMAIL.INI FILE ;;;
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=tls
error_logfile=error.log
pop3_server=
pop3_username=
pop3_password=
force_recipient=
hostname=
auth_username=[your-gmail-username]@gmail.com
auth_password=[your-gmail-password]
force_sender=[your-gmail-username]@gmail.com
;;; END SENDMAIL.INI FILE ;;;
Be sure to change the last three line above with the correct values. Save the file, then restart Apache for changes to take effect.
Note that any e-mail you send will have the sender as your gmail account, no matter what you specify as the sender for php mail(). So this is okay for local testing purposes, but is not ideal for live deployment.
[…] I used to create a live test site just to check this. But not anymore since i found this tutorial How to send email from XAMPP (PHP). […]
Very good article. It worked in my system with xampp 1.7.3
above confi is working but i m not got mail into my mail a/c
please guide me
nice one it works!!!
Warning: mail() [function.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\Brandon\register.php on line 34
i follow all the step that you teach..but it not work too..
is it my my php script have prob??
can you help me to check what is the problem and teach me?
your reply will be appreciate..thanks a lot 🙂
require_once(‘db.php’);
include(‘functions.php’);
include(‘settings.php’);
date_default_timezone_set (“Asia/Kuala_Lumpur”);
$date = date(“g:i a”);
if ( array_key_exists ( ‘_submit_check’, $_POST ) )
{
if ( $_POST[‘username’] != ” && $_POST[‘password’] != ” && $_POST[‘password’] == $_POST[‘password_confirmed’] && $_POST[’email’] != ” && valid_email ( $_POST[’email’] ) == TRUE )
{
if ( ! checkUnique ( ‘Username’, $_POST[‘username’] ) )
{
$error = ‘Username already taken. Please try again!’;
}
elseif ( ! checkUnique ( ‘Email’, $_POST[’email’] ) )
{
$error = ‘The email you used is associated with another user. Please try again or use the “forgot password” feature!’;
}
else {
$query = mysql_query( “INSERT INTO users (`Username` , `Password`, `date_registered`, `Email`, `Random_key`) VALUES (” . mysql_real_escape_string ( $_POST[‘username’] ) . “, ” . mysql_real_escape_string ( md5 ( $_POST[‘password’] ) ).”, ‘” . time () . “‘, ” . mysql_real_escape_string ( $_POST[’email’] ) . “, ‘” . random_string ( ‘alnum’, 32 ) . “‘)” );
$getUser = mysql_query(“SELECT ID, Username, Email, Random_key FROM users WHERE Username = ‘” . mysql_real_escape_string ($_POST[‘username’]).”‘”) or die(mysql_error());
if(mysql_num_rows($getUser)==1)
{
$row = mysql_fetch_assoc($getUser);
$headers = ‘From: ‘ . $site_email . “\r\n” .
‘Reply-To: ‘ . $site_email . “\r\n” .
‘X-Mailer: PHP/’ . phpversion();
$subject = “Activation email from ” . $domain_name;
$message = “Dear “.$row[‘Username’].”, this is your activation link to join our website. In order to confirm your membership please click on the following link: “.$url.”confirm.php?ID=”.$row[‘ID’].”&key=”.$row[‘Random_key’].” Thank you for joining”;
if ( mail($row[‘Email’], $subject, $message, $headers ) )
{
$msg = ‘Account created. Please login to the email you provided during registration and confirm your membership.’;
}
else {
$error = ‘I created the account but failed sending the validation email out.’;
}
}
else {
$error = ‘You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.’;
}
}
}
else {
$error = ‘There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match one another’;
}
}
I tried modifying the sendmail.ini file as instructed xrcmedia bt its still not working. Can u plz tel me how to configure it with Mercury/32.
I need ur help plz rpy
i couldn’t follow step after edit sendmail.ini..is it need to edit mercury and add gmail configuration in sendmail.ini. Thanks
hi my dear friend i am trying to do this from very time thanks for your help
because of you i succeed in it…………thanks a lot
its not working for me. the mail was not sent please help me
Reblogged this on Siva Balan.
Thanks a lot ! It Works
wow super cool!!!! it really works!!!! Thanks a lot!
I’m impressed, I must say. Rarely do I come across a blog that’s equally educative
and engaging, and let me tell you, you’ve hit the nail on the head. The problem is an issue that too few men and women are speaking intelligently about. Now i’m very happy I stumbled across this in my hunt for something regarding this.
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. uv1sm519643pbc.16 – gsmtp in C:\xampp\htdocs\test\email.php on line 38
Thank you for using our mail form
Im facing this prob. guys help me out from here..
This is really interesting, You’re a very skilled blogger. I have joined your rss feed and look forward to seeking more of your magnificent post. Also, I’ve
shared your website in my social networks!
I have implemented this and it says mail sent successfully but no mail is received.
Anyone have any idea whats going wrong :O, Please reply soon, i need this
thanks
I do not have this one on my sendmail.ini
# Mercury
#account Mercury
#host localhost
#from postmaster@localhost
#auth off
# A freemail service example
#account Hotmail
#tls on
#tls_certcheck off
#host smtp.live.com
#from [exampleuser]@hotmail.com
#auth on
#user [exampleuser]@hotmail.com
#password [examplepassword]
same here
Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you….I HAVE BEEN TRYING TO FIGURE THIS OUT FOR A WEEK!!! THANK YOU
[…] thanks to this link . His original post point me to the right direction. The only missing piece is port number in […]
It’s perfect time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you few interesting things or advice. Perhaps you can write next articles referring to this article. I desire to read more things about it!
Alojarse sobre hoteles románticos durante las vacaciones agrega nuestros recursos con eel fin dee
invertir en compras, paseos y futuro. Sin embargo evidentemente, solicita dde una búsqueda previa mucho más
y más sagaz también minuciosa que sin duda nos decidiéramos lucro opciones de
un costo desarrollado.
nama:siska darojatul usgaria
klaz:7e
no absen:37
Hello, i think that i noticed you visited my weblog so i got here
to go back the desire?.I’m trying to to find things to improve my website!I guess its ok to
use a few of your concepts!!
Very good article! We will be linking to this great content on our
site. Keep up the great writing.
Quality articles is the important to invite the viewers to go to see the web page, that’s what this web site is
providing.
Bitcoins sure are gathering allot of interest recently.
It is in point of fact a nice and helpful piece of info.
I am happy that you shared this useful information with us.
Please stay us up to date like this. Thanks for sharing.
I cant find Mercury in sendmail.ini maybe your tutorial is out of date or maybe I do sth wrong?
Gmail Customer Support Service we have Read Moreelp you 24*7 any types of gmail problem.
Hi thanks for sharing your blog email sending related call toll free Contact Number 1-855-286-1922
this was a pathetic solution, here is simple solution https://www.youtube.com/watch?v=TO7MfDcM-Ho
thank you very good
please help me…is not work…..!
Savvy commentary – Coincidentally if others want a NZ INZ 1146 , my family filled out and esigned a template version here http://goo.gl/0DT3fC
Didnt work on me i have a windows 7 ultimate
Hi, everything is going well here and ofcourse every one is
sharing information, that’s genuinely fine, keep up writing.
hey guys …
to send mail in php using xampp server or localhost first follow these steps…
Turn On the less secure apps by clicking on…… https://www.google.com/settings/security/lesssecureapps
after then watch the youtube video ..your mail to be sent 100% by this video….
You’re so interesting! I do not believe I have read something like
this before. So wonderful to discover another person with
some original thoughts on this issue. Seriously..
thank you for starting this up. This web site is something that
is needed on the web, someone with a little originality!
We hired a local business to do the SEO and not long after the blog
had lost a lot of traffic, did I pick a bad SEO’er?
[…] SMTP per inviare e-mail attraverso il server di posta ISP? Sto usando XAMMP, come si fa a fare che? expertester.wordpress.com/2010/07/07/… Funzione Mail non funziona sul computer […]
[…] via vos serveurs de messagerie du FAI? Je suis à l'aide de XAMMP, comment fait-on pour le faire? expertester.wordpress.com/2010/07/07/… La fonction Mail ne fonctionne pas sur la machine […]
Спасибо за информацию!!!!!