barbs75 Posted April 1, 2008 Share Posted April 1, 2008 Hi guys, bit of a no-brainer.... i have email functions on my website which i am writing and testing on my local server, which send a password to a user to their email address. When running these scripts on my local server, am i right in saying that these scripts wont work when running on the local server, they will only send an email when they are running 'live' or remotely... just a thought, because i get an error when running a part of a script which executes a piece of code which is running locally, but obviously might be throwing an error because thescript cannot execute properly... any thoughts?? as i said probably a no-brainer.. cheers Craig Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted April 1, 2008 Share Posted April 1, 2008 mail functions on work when properly configed so to answer your question I have no clue if your local server config is right for email sending. Quote Link to comment Share on other sites More sharing options...
dmccabe Posted April 1, 2008 Share Posted April 1, 2008 that depends I think on you set up the mail server info on your localhost. I am running a script on my local machine, but have my smtp server setup so it will send to any address Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 1, 2008 Author Share Posted April 1, 2008 hey thanx for your reply, how do i go about setting up emailing scripts etc on apache server for example? do you know? Cheers Craig Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 you can send email via mail() or PEAR:Mail functions. look it up on the php.net website. if you are using SMTP you will need an SMTP server to relay the email, you can use your own computer with programs like 1st free smtp. just google SMTP Server Free. Most wont work and are poorly designed but some out there can be called Free Gems What error is your script giving? you can turn your local server into the same as any other remote server out there. most commercial hosts use mostly default settings, and let you configure them yourself. Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 1, 2008 Author Share Posted April 1, 2008 yo uniflare, right, i have been using the mail() function within php to send emails to users, (this is used for an activation email ad for a forgotten password feature) and example of the code i have been executing as follows (shown in a function) function notify_password($username) // notify the user that their password has been changed { $sql = "SELECT email FROM customer WHERE username='$username'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $check_user = $row['email']; $user_exist = mysql_num_rows($result); if(!$user_exist) { throw new Exception('Could not find email address.'); } else if ($user_exist==0) { throw new Exception('Could not find email address.'); // given email address not in db } else { $useremail = $check_user; echo 'the value of email is'.$useremail; $yoursite = 'www.go4home.co.uk'; $webmaster = 'Craig Barber website Manager'; $youremail = 'craig@go4home.co.uk'; $subject = "You have successfully reset your $yoursite password..."; $message = "Your go4home password has been changed to $password \r\n" ."Please change it next time you log in. \r\n Thanks, $webmaster"; if (mail($useremail, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion())) { return true; } else { throw new Exception('Could not send email.'); } } } i get an error thrown when this function is called saying that it could not send email, so obviously the mail script isn't working, and the other script that i have used, just doesn't execute the mail script, no errors or anthing, just doesnt work.. i have been reading an article on the internet, to allow mailing scripts to be executed by configuring your SMTP server, the url to this link is http://www.thesitewizard.com/archive/php4install.shtml where it quotes: Use an ASCII text editor (such as Notepad, which can be found in the Accessories folder of your Start menu) to open "php.ini". You may need to make the following changes to the file, depending on your requirements: Your SMTP Server If you want the mail() function to actually send out email when you test your own PHP scripts, search for the section of the file beginning with the line "[mail function]" (without the quotes). You should come across a section that looks something like the following: [mail function] ; For Win32 only. SMTP = localhost ; For Win32 only. sendmail_from = me@localhost.com Change it to point to your SMTP server and email account. For example, if your SMTP server is "mail.yourisp.com" and your email address is "youremail@somewhere-or-other.com", change the code to: [mail function] SMTP = mail.yourisp.com sendmail_from = youremail@somewhere-or-other.com Note that after you do this, when your script tries to use the mail() function, you will need to be connected to your ISP for the function to succeed. If you do not modify the above lines and attempt to use mail() in your script, the function will return a fail code, and display (or log) the error (depending on how you configure php.ini to handle errors). so reading this article, im confused with what the SMTP server is. if i wanted to say email from my hotmail account in the 'sendmail_from' would i put 'blahblah@hotmail.com' but then what do i put for the SMTP?? im confused with this... are you suggesting that i need a piece of software such as '1st free smtp'??? REALLY CONFUSED ??? setting my local server to a remote server would be great, but thats a pretty tough challenge right?? cheers Craig Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 you would use an SMTP server similarly to MySQL server, its a program that runs on a system (or 'server') that can send and recieve SMTP emails. localhost would be the SMTP server on your local machine, you can download an SMTP server from lots of places and some are free. if you are using hotmail you dont need a local SMTP server. i do not think you can use hoptmail to send SMTP mails though. Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 1, 2008 Author Share Posted April 1, 2008 hey, i downloaded the '1st free smtp server' which allows you to check SMTP gateways, which then checks if port 25 is open by your ISP. it then allows you to chek your hostname aswell, which is a really long string, which is then put in your gateway list. What do i then put in my php.ini file?? do i put the smtp server as this hostname? or does it remain localhost? cheers Craig Quote Link to comment Share on other sites More sharing options...
trq Posted April 1, 2008 Share Posted April 1, 2008 Seriously, unless you know what you are doing setting up an smtp server on your local machine is a bad idea. Huge security risk. Most isp's provide you with access to an smtp server. Simply use there details in your php.ini. Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 should remain localhost - thorpe is correct smtp's can be overloaded easily. it would be safer to use your ISP SMTP Gateway, what is your ISP? Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 2, 2008 Author Share Posted April 2, 2008 hey, my ISP is virgin media, i have virgin media boradband. I checked out my ISP smtp on the net, it was listed as 'Smtp.ntlworld.com' and also 'smtp.virgin.net' What i am trying to do at the moment is use my email which is through the hosting company i'm using, 1&1. As the mySQL database i have connected on their host isnt working and they are currently fixing the problem, that is why i am testing locally and want to use my mail scripts to see if they are working. So if i want to use my email account that i have with my domain from them, i need their smtp server name right? and place that in the php.ini file? their smtp is 'auth.smtp.1and1.co.uk' cheers Craig Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 2, 2008 Share Posted April 2, 2008 have you tried it? try it if it doesnt work then tell us... We could shoot hypothetical questions and theories for years, but writing and testing actual code is faster and easier on everyone. To use your ISP set your smtp server settings in php.ini the the smtp server. you may need some sort of authorization user/pass - unfortunately ive never used authorization with smtp so i cant help you there :/ To use your hosting company it would be the same method OR just ask your hosting company for their PHP.ini settings for their SMTPServer/Port as it may be either Local Only or on a different port or something. --- hope this helps, Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 2, 2008 Author Share Posted April 2, 2008 Hey Uniflare, cheers so much for your help so far, really appreciate it! Right, i have been fiddling round for ages, and have tried changing my php.ini file many times, and have even installed PEAR on php and tried using the PEAR mail function, but that doesnt work either, really getting stuck... What i have done, to use my email account from my host, i have changed my php.ini file as follows: [mail function] SMTP = auth.smtp.1and1.co.uk smtp_port = 25 sendmail_from = craig@go4home.co.uk the SMTP is the correct server that they have stated on my account. This doesn't work! when i perform a simple mail() script as follows, ii returns as 'false' i am running these scripts locally on my localhost using Apache server, and not on the 1and1 server here is the email script i have been using, just to test this out: emailExample.php <?php $to = 'craigbarber75@hotmail.com'; $mysite = 'www.go4home.co.uk'; $webmaster = 'Craig Barber website Manager'; $myemail = 'craig@go4home.co.uk'; $subject = "You have successfully reset your $mysite password..."; $message = "Your go4home password has been changed to $password \r\n" ."Please change it next time you log in. \r\n Thanks, $webmaster"; $headers = "From: $myemail\r\nReply-To: $myemail"; if(mail($to, $subject, $message, $headers)) { echo 'you have successfully sent an email'; } else { echo 'unlucky, you have failed to send an email'; } ?> the code looks right, so there's obviously something wrong with the set up sorry if im being a pain, i just can't figure this out cheers Craig Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 2, 2008 Share Posted April 2, 2008 look in the apache error.log for errors, also i think you are missing necessary headers: $headers = "From: \"".$myemail."\" <".$myemail.">\n"; $headers .= "Return-Path: <".$myemail.">\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n"; ---- Does your smtp server require authentication? can you use outlook with it? Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 2, 2008 Share Posted April 2, 2008 No problem not suffering any pain here Quote Link to comment Share on other sites More sharing options...
barbs75 Posted April 2, 2008 Author Share Posted April 2, 2008 Hey, i'm feeling some SERIOUS pain over here i can tell you!! right, my email account with 1and1, i have set up on outlook, that all works fine, i can send and receive emails without any problems. I added the script you suggested for the $headers variable, and still no joy, the mail() script still returns false!! any ideas? Cheers Craig Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 2, 2008 Share Posted April 2, 2008 check the error.log in your webservers logs folder. usually mail returns the actually error rather than just false (i mean a fatal error). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.