I've been on a few other forums for a while, getting help for projects and helping some people etc, but I've never seen a clear and useful post about setting up an SMTP server and getting the mail function to work properly.
Some info about my system:
Windows XP Home (SP2)
Apache 2.0.XX
PHP 5
MySQL 4.1
ActivePerl 5.8.7 (If anyone knows how to set this up with apache, please send me a pm, thanks)
I'd really like if someone could post a few links or someinfo on how to set up php's mail stuff
From what responses I've gotten in the past, I think I need an SMTP server installed on my computer, when I googled, the only results that I seemed to get were servers I would have to pay for. I'd also like to know about configuring PHP's mail functions (php.ini options) so that it will work corectly
Thanks for any replies
I'd just like to add that, if your reply is critisizing me for asking, or saying 'google it', it is not welcome, I'd like useful responses, or none at all, Thank you.
bradgrafelman
06-28-2005, 05:15 PM
Windows XP Home? This would indicate, to me, that you are a simple user at home attempting to run a website, using a simple home computer, connected to a simple residential ISP.
Other than the various warnings I would voice concerning the EULA, TOS, AUP, etc. your ISP might hold that strictly prohibits any webserver or SMTP server (as most ISP's do, especially broadband), I would ask you one thing:
Why not use your ISP's SMTP server?
If your ISP provides you with an e-mail address and POP3 access, then you can configure PHP to use their SMTP server to send mail for you. If you look in your php.ini configuration file, you'll see two settings, like so:
[mail function]
; For Win32 only.
SMTP = mail.telstar-online.net
; For Win32 only.
sendmail_from = (link in profile)
Simply fill in the correct values (it's probably just like mine; "mail." followed by your ISP's server, though if you can't find the correct address let me know) for both settings and try a simple call to mail (http://www.php.net/manual/en/function.mail.php)().
You might take note that PHP's mail() function does not authenticate with the SMTP server, nor does it support such authentication (at least in PHP 4, no clue about 5). If your ISP requires SMTP authentication, you will probably need to look for an alternative to PHP's built-in function.
Such an alternative might be the PHPMailer (http://phpmailer.sourceforge.net/) class.
camowel
06-28-2005, 07:09 PM
Thanks for reminding me about the server thing with my ISP, forgot about it, and yes, I'm quite a simple user tyring to develop my site. However I've set my firewall to block Apache's access to the internet, and I have disabled my port 80 forwards a while ago (after I stumbled on to that regulation looking for something completely unrelated)
I'm going to try and fill in the mail stuff, I just want to get this working properly so I know it will work when I upload my site to a remote server (lots of work to go until then)
Thank you very much for your response, its the first straight answer regarding this subject I've gotten (I've been asking around other forums for months)
If anyone knows, would this work with a gmail account (smtp.gmail.com)? I know you can connect to it and send mail through outlook etc, but would it work for this type of mail?
Thanks again for the great answer!
bradgrafelman
06-28-2005, 07:15 PM
Well, there are RFC standards out there, I don't see why G-Mail should be any exception.
One tip that contradicts the manual (but is required when dealing with certain servers, GMail being one of these servers) is that some non-RFC standard servers dont use "\r\n" as delimiters in headers, but instead use "\n". Keep this in mind if you have custon headers in your call to mail() !
camowel
06-28-2005, 07:25 PM
Wow thanks :) I'll be sure to remember that, depending on which server I choose to use for this,
That gave me an idea, what do you think of something like this:
<?
$pattern = '/\w+\\.([a-zA-Z_\\-]+)\\..+/';
preg_match($pattern, get_ini('SMTP'), $matches);
$server = $matches[1];
switch ($server) {
case 'gmail':
$linebreak = '\n';
case 'ispname':
$linebreak = '\r\n';
}
I set a few variables above that and didn't display them (to avoid spam)
Here are the results using my ISP:
SMTP = smtp.myisp.com
Output from the script:
Your using myisp
Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.myisp.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache2\htdocs\index.php on line 32
Once again I've replaced my ISP for a bit of spam protection
SMTP = smtp.gmail.com
Output from script:
Your using Gmail!
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first p4sm2159249nzc in C:\Apache2\htdocs\index.php on line 32
It seems like the gmail problem would be the easiest to solve to me, as my ISP need authentication (which is probably hard to do)
I'll be back online later, so no rush
Thanks once again for your help!
bradgrafelman
06-28-2005, 09:40 PM
Actually, no - dealing with simple authentication with PHPMailer (link in one of my above posts) would be much, much easier than dealing with Gmail, because of one fact: G-Mail uses a secure connection.
Try taking a look at PHPMailer. You'll have to configure it, but it's making me nervous that it said it "Failed to connect" rather that it failed to send the mail (due to lack of authentication). Are you sure you used the correct SMTP address for your ISP? If you aren't sure, open your mailing software and look at the SMTP Server setting (and port!). If all else fails, call your ISP and ask them to give you the SMTP server and port number because you've lost it, need to reconfigure, whatever, though I would advise that you not say it's for a PHP script that sends mail through their servers!
camowel
06-28-2005, 11:53 PM
I've set up the smtp server and port properly, now I get:
Warning: mail() [function.mail]: SMTP server response: 530 authentication required - for help go to ***** in \Apache2\htdocs\index.php on line 32
So I'm looking at PHPMailer
If you know of any tutorials or articles on authenticating, that would be great too, I like making my own classes over using pre-made ones, (I've acctually tried PHPMailer before, it didn't work out too well because I didn't have things set up properly ;) )
camowel
06-29-2005, 12:55 AM
Thanks sooooo much for your help!
With a bit of reading through the PHPMailer documentation (and some clever clever thinking) I managed to get it working, and authenticating with my ISP's SMTP server.
Thank you once again, I have been wanting to get mail() to work for years! (yup.. ever since I found out it was possible to send mail with php I've wanted to, never had any good support before though).
zarkolazarov
04-29-2007, 10:47 PM
Windows XP Home? This would indicate, to me, that you are a simple user at home attempting to run a website, using a simple home computer, connected to a simple residential ISP.
Other than the various warnings I would voice concerning the EULA, TOS, AUP, etc. your ISP might hold that strictly prohibits any webserver or SMTP server (as most ISP's do, especially broadband), I would ask you one thing:
Why not use your ISP's SMTP server?
If your ISP provides you with an e-mail address and POP3 access, then you can configure PHP to use their SMTP server to send mail for you. If you look in your php.ini configuration file, you'll see two settings, like so:
Simply fill in the correct values (it's probably just like mine; "mail." followed by your ISP's server, though if you can't find the correct address let me know) for both settings and try a simple call to mail (http://www.php.net/manual/en/function.mail.php)().
You might take note that PHP's mail() function does not authenticate with the SMTP server, nor does it support such authentication (at least in PHP 4, no clue about 5). If your ISP requires SMTP authentication, you will probably need to look for an alternative to PHP's built-in function.
Such an alternative might be the PHPMailer (http://phpmailer.sourceforge.net/) class.
I happend to have the exact same problem with my smtp configuration and this totally saved the day. Thank you very very much
rehriff
11-25-2009, 06:22 AM
How To: PHP Sendmail and XAMPP on Windows
It can be difficult getting the PHP’s default mail functions to work when you run an apache server on windows instead of a unix environment. I ran into this problem with my server (running XAMPP), and thought others may benefit from a quick how-to. Another slight problem I had to get working was using an SMTP server that requires SSL connections (gmail for one). I didn’t realize that most recent XAMPP releases have sendmail built in already. This takes part of the hassel out, but we still have some configuring to do.
First, ensure that you have an XAMPP release that does include the fake sendmail program. [More details here]
Next, go to the XAMPP directory (often C:\xampp\), then open the ’sendmail’ subdirectory. You’ll most likely see the following files (default):
sendmail.exe
readme.html
sendmail.ini
sendmail_example.ini
license.html
Open the file sendmail.ini – this is where all of your SMTP server configurations will go, for example: SMTP Username, Password, Host, Port, etc
My sendmail.ini file looks something like this:
; configuration for fake sendmail
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=465
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
default_domain=brettshaffer.com
error_logfile=error.log
; if your smtp server requires authentication, modify the following two lines
auth_username=<USERNAME / EMAIL ADDRESS HERE>
auth_password=<PASSWORD HERE>
Note that this is a very simple setup. The variable names are fairly obvious, so simply fill in the SMTP server, port, ssl mode, username, password, and default domain / error log if you’d like.
GMail requires an SSL connection, so my config was setup to use SSL port 465 and smtp_ssl=auto. If SSL is not necessary for your SMTP server, simply set smtp_ssl=none.
Once the configuration is setup, make sure to save changes, then exit.
If you are going to use SSL connections, you will need two additional files, available here " http://glob.com.au/sendmail/sendmail-SSL.zip" (as of March 2009) – if this link no longer works, use the contact form and let me know.
Extract the two compressed files (libeay32.dll and ssleay32.dll) to the same directory as sendmail.exe (for me, C:\xampp\sendmail\)
Now, everything on the sendmail’s end is setup – now we just need to let the server know its there!
Edit your PHP.ini file:
XAMPP installations often have multiple files. If you are doubtful of the correct one, you can always go through and change them all. But before you do that, change the php.ini in \xampp\apache\bin\.
Look for the following line:
sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”
Uncomment the line (if already commented) by removing the semicolon at the start.
Ensure that the path to sendmail.exe is correct (this is correct for me).
Save and exit php.ini
Restart the apache server and everything should work!
Comment if you have a question.
mugishaissa
11-29-2009, 11:26 AM
Hey guys, help me with this, i'm using xamp server on window vista but i can't connect. I keep on getting the error message below?
If you have any clues, please help
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\firstmail.php on line 3
bradgrafelman
12-04-2009, 05:06 AM
If you have any clues, please helpHere's a big one: read the above thread. :)
haijerome
07-26-2010, 09:25 AM
How To: PHP Sendmail and XAMPP on Windows
It can be difficult getting the PHP’s default mail functions to work when you run an apache server on windows instead of a unix environment. I ran into this problem with my server (running XAMPP), and thought others may benefit from a quick how-to. Another slight problem I had to get working was using an SMTP server that requires SSL connections (gmail for one). I didn’t realize that most recent XAMPP releases have sendmail built in already. This takes part of the hassel out, but we still have some configuring to do.
First, ensure that you have an XAMPP release that does include the fake sendmail program. [More details here]
Next, go to the XAMPP directory (often C:\xampp\), then open the ’sendmail’ subdirectory. You’ll most likely see the following files (default):
sendmail.exe
readme.html
sendmail.ini
sendmail_example.ini
license.html
Open the file sendmail.ini – this is where all of your SMTP server configurations will go, for example: SMTP Username, Password, Host, Port, etc
My sendmail.ini file looks something like this:
; configuration for fake sendmail
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=465
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=auto
default_domain=brettshaffer.com
error_logfile=error.log
; if your smtp server requires authentication, modify the following two lines
auth_username=<USERNAME / EMAIL ADDRESS HERE>
auth_password=<PASSWORD HERE>
Note that this is a very simple setup. The variable names are fairly obvious, so simply fill in the SMTP server, port, ssl mode, username, password, and default domain / error log if you’d like.
GMail requires an SSL connection, so my config was setup to use SSL port 465 and smtp_ssl=auto. If SSL is not necessary for your SMTP server, simply set smtp_ssl=none.
Once the configuration is setup, make sure to save changes, then exit.
If you are going to use SSL connections, you will need two additional files, available here " http://glob.com.au/sendmail/sendmail-SSL.zip" (as of March 2009) – if this link no longer works, use the contact form and let me know.
Extract the two compressed files (libeay32.dll and ssleay32.dll) to the same directory as sendmail.exe (for me, C:\xampp\sendmail\)
Now, everything on the sendmail’s end is setup – now we just need to let the server know its there!
Edit your PHP.ini file:
XAMPP installations often have multiple files. If you are doubtful of the correct one, you can always go through and change them all. But before you do that, change the php.ini in \xampp\apache\bin\.
Look for the following line:
sendmail_path = “C:\xampp\sendmail\sendmail.exe -t”
Uncomment the line (if already commented) by removing the semicolon at the start.
Ensure that the path to sendmail.exe is correct (this is correct for me).
Save and exit php.ini
Restart the apache server and everything should work!
Comment if you have a question.
Thanks a lot ..... you saved my day ....
PHP Builder
Copyright Internet.com Inc. All Rights Reserved.