I want to know if it is possible to send emails from localhost. If yes, how? I want to send emails from my localhost using my gmail account. I have a Mac OS X Yosemite Version 10.10.1 and I am running XAMPP 5.6.3-0.
Thanks!
You can use PHP mailer and not configure SMTP on your machine or you can follow this instructions to configure sendmail with GMAIL.
I like option 2 :) (Just for fun). Of course the first option is easier.
First go to the path that you installed Xampp application. By default it is C:\xampp\.
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.
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"
Save the php.ini file and restart the Apache process. This is
necessary for the configuration to take place.
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.
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.
Find smtp_server and write the Gmail SMTP address in front of
that.
Find smtp_port and write the Gmail SMTP port in front of that.
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 .
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.
Related
I have scoured every tutorial out there on how to do this and I am still not getting the desired result so there must be some detail I am missing. The mail() function returns as though it succeeded however I NEVER GET ANY EMAILS in my sent or inbox
In a nutshell I have done the following:
Copied Sendmail.exe and Sendmail.ini along with their dlls to a
folder named Sendmail that resides in c:\program files\wamp\bin\
Edited the sendmail.ini to point to port 465 (for gmail) and smtp to
smtp.gmail.com, also configured the correct user name and password
authentication fields, as well as set smtp_ssl to ssl
Enabled the php_openssl and php_sockets under php extensions in wamp
edited php.ini [mail function] parameters. I commented out everything in win32 and then set smtp_path = c:\program files\wamp\bin\sendmail\sendmail.exe -t" then restarted all serviced on WAMP
Logged into my gmail account and enabled IMAP
Can anyone please help me out here???
This is from : http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
I followed the steps and was able to send emails from wamp server. Your problem seems to be the name of the folder "Program Files" it has a space in it.
If the path to the sendmail.exe contains “space” (for example, “C:\Program Files\PHP\sendmail\”) then Apache would not be able to locate it. So, either store the sendmail.exe at a “non-spaced” location/path OR write the path in DOS style “C:\Progra~1\PHP\sendmail\” in the php.ini (sendmail_path = "C:\Progra~1\PHP\sendmail\sendmail.exe -t -i").
Have a look at > http://phpmailer.worxware.com/?pg=examplebgmail
and https://github.com/Synchro/PHPMailer
It's a lot easier and it saves a lot of time to send using frameworks rather than attempting to tinker wamp on your own.
(on a side note, it's MUCH easier to send gmail via smtp with python)
Good luck!
I have coded a web site from scratch with XHTML, using Windows XP Pro, and this includes a contact form in PHP. The web site is in a XAMPP folder on the C drive and being run under localhost on my computer at home.
I want to test the form by sending an email test message from it to my live email address. I have tried this by changing the SMTP = localhost in the PHP .ini file to my ISP server address, activating the line,
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
and adding a semicolon to the beginning of the line below,
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
I have placed my live email address in the contact form code like so:
<?php
//send email
if(mail('my#emailaddress.net','Contact
form',$msg, 'From:postmaster#localhost')) {
?>
Then I tried another way by placing my email address under the if(POST) function instead:
<?php
if($_POST) {
$fName = $_POST['fName'];
$fEmail = $_POST['fEmail'];
$fComments = $_POST['fComments'];
$fCaptcha = $_POST['fCaptcha'];
$random_string = $_POST['random_string'];
$to = "myemailaddress#myisp.net";
?>
And changed the mail function lower down in the script accordingly:
<?php
//send email
mail($to, $fName, $fEmail, $fComments);
if(mail($to,'Contact form',$msg, 'From:postmaster#localhost')) {
header("Location: ../email-thankyou.htm");
?>
When I clicked on the submit button, it generated an error page from my ISP server the first time, and from the Firefox browser during later attempts, so something is happening, but in looking at my live email account there is no sign of my message arriving.
I also found that the form itself disappeared and I was left with just the background colour of the page, when clicking on the submit button when I tried the second method.
I have searched through Stack Overflow for similar queries, and tried a few suggestions without success.
I am using XAMPP version 3.1.0.3.1.0. Although I am conversant with XHTML coding, I am a complete novice with regards to PHP programming, as this project using PHP is my first effort to get to grips with it, and would really appreciate any help and advice given, particularly as to writing the mail($to, and if(mail($to, out correctly.
I have now found the answer to this question by downloading and installing smtp4dev 2009 on my C drive. With this little program in conjunction with XAMPP, I can now test my contact form and it receives the messages successfully. The only other thing I needed to to was to configure the XAMPP php ini file as follows:
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
As far as the earlier problem of the form disappearing when clicking on the Send button, is concerned - part of the script was in the wrong place and after some trial and error in positioning it, this problem was solved.
You want to set up mercury or a local mail server to be able to do this. Mecury comes installed with xampp.
http://www.youtube.com/watch?v=VU4PT7xMSO0
$res= mail('myemailaddress#live.com', 'Email verification ','This is my own text');
print $res;
I have tried to send mail to my email id. I have 1 on page. Looks like it's working but it really did not work.
php.ini:
define_syslog_variables = Off
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP = localhost
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mymailaddressishere#live.in
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program files\xampp-portable) fakemail and mailtodisk do not work correctly.
; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path.
; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"\xampp-portable\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the \xampp-portable\mailoutput folder
sendmail_path = "\xampp-portable\mailtodisk\mailtodisk.exe"
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
;mail.log = "\xampp-portable\php\logs\php_mail.log"
[SQL]
I want to know that how I can trace what happen to my code. If I need to do some settings in my local php server then tell me about them.
I am using xampp portable "Run as administrator".
There is a line in your file that says:
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the \xampp-portable\mailoutput folder
sendmail_path = "\xampp-portable\mailtodisk\mailtodisk.exe"
In my XAMPP installation, I found that the comment was wrong. You actually have to uncomment the line if you want to use mailToDisk, and the mail is actually written to /tmp/mailoutput.
I can't use a comment system, so I can only post it here. but I think this is not the answer you are looking for.
XAMP might not be able to send email. Most localhost testing environment, such as xamp, or wamp are not able to send email. They need to be set up as mail server first. You could try setting them as mail server, but I think it's easier to just get a free hosting (with some "ugly" subdomain name), and put your script there and try to send mail.
I am going out on a limb by saying this: You don't have an SMTP server installed, let alone running. Just because your php.ini says mail() will use SMTP # localhost:25 doesn't really mean it is installed and running. The mail() function will return true even if it doesn't actually send the letter.
If you have installed an SMTP server (which doesn't come packaged as of now with XAMPP), and have it running, then I apologize. Please post which SMTP server you are using and your services list to ensure it is running. Then it will be easier to diagnose.
EDIT
Just tested on my computer without SMTP server being set up:
$a= #mail('sales#ellsworthpublishing.com', 'asdf', 'asdf');
if(!$a)
echo'False';
else
echo'True';
The output is True.
Is there a way that I can configure the WAMP server for PHP to enable the mail() function?
Configuring a working email client from localhost is quite a chore, I have spent hours of frustration attempting it. I'm sure someone more experienced may be able to help, or they may perhaps agree with me.
If you just want to test, here is a great tool for testing mail locally, that requires almost no configuration:
http://www.toolheap.com/test-mail-server-tool/
Install Fake Sendmail (download sendmail.zip).
Then configure C:\wamp\sendmail\sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=465
auth_username=user#gmail.com
auth_password=your_password
The above will work against a Gmail account.
And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
Using an open source program call Send Mail, you can send via wamp rather easily actually. I'm still setting it up, but here's a great tutorial by jo jordan. Takes less than 2 mins to setup.
Just tried it and it worked like a charm! Once I uncommented the error log and found out that it was stalling on the pop3 authentication, I just removed that and it sent nicely. Best of luck!
You need a SMTP server to send your mail. If you have one available which does not require SMTP authentification (maybe your ISP's?) just edit the 'SMTP' ([mail function]) setting in your php.ini file.
If this is no option because your SMTP server requires authentification you won't be able to use the internal mail() function and have to use some 3rd party class which supports smtp auth. e.g. http://pear.php.net/package/Mail/
I tried Test Mail Server Tool and while it worked great, you still need to open the email on some client.
I found Papercut:
https://github.com/ChangemakerStudios/Papercut-SMTP
(updated URL for 2021)
For configuration it's easy as Test Mail Server Tool (pratically zero-conf), and it also serves as an email client, with views for the Message (great for HTML emails), Headers, Body (to inspect the HTML) and Raw (full unparsed email).
It also has a Sections view, to split up the different media types found in the email.
It has a super clean and friendly UI, a good log viewer and gives you notifications when you receive an email.
I find it perfect, so I just wanted to give my 2c and maybe help someone.
Sendmail wasn't working for me so I used msmtp 1.6.2 w32 and most just followed the instructions at DeveloperSide. Here is a quick rundown of the setup for posterity:
Enabled IMAP access under your Gmail account (the one msmtp is sending emails from)
Enable access for less secure apps. Log into your google account and go here
Edit php.ini, find and change each setting below to reflect the following:
; These are commented out by prefixing a semicolon
;SMTP = localhost
;smtp_port = 25
; Set these paths to where you put your msmtp files.
; I used backslashes in php.ini and it works fine.
; The example in the devside guide uses forwardslashes.
sendmail_path = "C:\wamp64\msmtp\msmtp.exe -d -C C:\wamp64\msmtp\msmtprc.ini -t --read-envelope-from"
mail.log = "C:\wamp64\msmtp\maillog.txt"
Create and edit the file msmtprc.ini in the same directory as your msmtp.exe file as follows, replacing it with your own email and password:
# Default values for all accounts
defaults
tls_certcheck off
# I used forward slashes here and it works.
logfile C:/wamp64/msmtp/msmtplog.txt
account Gmail
host smtp.gmail.com
port 587
auth on
tls on
from ReplaceWithYourEmail#gmail.com
user ReplaceWithYourEmail#gmail.com
password ReplaceWithYourPassword
account default : gmail
I used Mercury/32 and Pegasus Mail to get the mail() functional. It works great too as a mail server if you want an email address ending with your domain name.
I'm currently trying to debug an Elgg-based website (I didn't develop it) and I would like to send the emails directly from local development machine (WinXP). I'm running WAMP with Apache 2.2.11 and PHP 5.3.0
After some searching, the simplest solution that I've come across is using fake sendmail to forward it to my GMail/Google apps account via SMTP and let it do the sending. The problem is that I get no errors whatsoever, but the email isn't being sent.
Here's what I did:
Copied the sendmail.exe and sendmail.ini to a subfolder in WAMP
Configured it via sendmail.ini (the configuration settings are ok)
Edited php.ini to add the path to sendmail.exe
sendmail_path = "C:\Program Files\wamp\bin\sendmail\sendmail.exe -t"
Commented out the windows SMTP settings in php.ini
; SMTP = localhost
; smtp_port = 25
; sendmail_from = xxx#domain.com
; mail.force_extra_parameters =
The mail.log file shows the following:
mail() on [C:\Program Files\wamp\www\mail.php:9]: To: xxx --
Headers: From: xxx Reply-To: xxx X-Mailer: PHP/5.3.0
My guess is that the problem is that the default Windows option (to specify the server and not the sendmail utility) is not overriden. In phpinfo() I still get the SMTP -> localhost and smtp_port -> 25 options, even though I commented them.
If anyone managed to get this working, I'd really appreciate some help. In my opinion, using fake sendmail is a lot simpler than installing a mail server on your machine.
Thanks!
P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.
I've gotten it to work eventually. The problem was that PHP had a bug in parsing .ini files with spaces in the path (for sendmail). It was fixed in version 5.3.0, but the manual had no info on this.
So, yes, it is possible to use sendmail with PHP on Windows :D.
Thank you all for your time!
Make sure you have SMTP Service running on your local machine and that SMTP Port(25) is opened.
Have a check on the services (Run->services.msc) and look for Send Mail Transfer
If you cannot find SMTP on the services list, you must install it:
To add,
Run->appwiz.cpl->Add Remove Windows components->IIS->Details->SMTP
I am not sure if this helps or not, what i used to do in these scenarios was to setup , outlook on my machine and have it set to get emails from the pop every 5 mins or so, that way my ip/machine was authenticated against the pop and if i just set the :
SMTP = localhost
smtp_port = 25
in php.ini , the mail function worked fine. So in your case just set your outlook to work with a pop and use that smtp in php.ini and hopefully it should work. I havent tested this will GMail though.
P.S. Please don't suggest PHPMailer and the like, because I have to use the mail() function. That's how Elgg works.
...unless you're using a plugin that changes this behaviour:
http://community.elgg.org/pg/plugins/costelloc/read/16498/phpmailer