Jump to content

Basic PHP Mail Help


JJ2K

Recommended Posts

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.  :D

 

 

Link to comment
https://forums.phpfreaks.com/topic/180488-basic-php-mail-help/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.