JJ2K Posted November 5, 2009 Share Posted November 5, 2009 Hi, I'm new to the PHP scene and could do with a bit of basic guidence. Basically i'm just testing out sending e-mails, I use XAMPP for all of my PHP testing (i'm on Windows XP SP3) OK so basically I copied and pasted directly from many sites some e-mail code, but they all failed, here's a quick example of one: $to = '[email protected]'; $subject = 'Test email'; $message = "Hello World!\n\nThis is my first mail."; $headers = "From: [email protected]\r\nReply-To: [email protected]"; $mail_sent = mail( $to, $subject, $message, $headers ); echo $mail_sent ? "Mail sent" : "Mail failed"; Obviously I replace the $to field with my e-mail address (which is an @live.co.uk e-mail address). But on testing this I get the following error: 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 myfile.php on line 40 Now I know there's not a problem with the code, i'm missing some basic education on how the mail system works I tihnk. Is it just the fact I am using XAMPP and testing on my localhost so it won't work? If I was ever to buy a domain/hosting and tested out this code in the real world would it work then? Or is it down to the e-mail address i'm sending it to (@live.co.uk)? In addition if anyone has some nice educational links on the issue/mail command i'd be happy to read through them in order to increase my understanding! Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/180488-basic-php-mail-help/ Share on other sites More sharing options...
waynew Posted November 5, 2009 Share Posted November 5, 2009 The problem is that your local server isn't configured to support the sending of emails. Try your script on a free hosting website such as http://000webhost.com. Link to comment https://forums.phpfreaks.com/topic/180488-basic-php-mail-help/#findComment-952149 Share on other sites More sharing options...
JJ2K Posted November 5, 2009 Author Share Posted November 5, 2009 Thanks works fine when tested on a webhost. Is that all is needed to send mail (check PHP code in 1st post), surely there's more complications? I know I should use Captcha/Random Maths Questions along with checking the refferer URL for security but is there anything else I should know? I'm basically going to use one eventually to send user details from a submitted form to my e-mail address.. Link to comment https://forums.phpfreaks.com/topic/180488-basic-php-mail-help/#findComment-952154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.