Send mail at localhost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GiaTuan
Forum Newbie
Posts: 14
Joined: Sat Oct 01, 2011 1:19 am

Send mail at localhost

Post by GiaTuan »

I have successfully sent mail.Yesterday, I received mail from php.Today,I can not find it in the mail box and spam.I know PHPMailer.But I want to try the mail function at localhost.
my code:

Code: Select all

<?php
   ini_set("SMTP","localhost");
   ini_set("SMTP_PORT", 25); 
   ini_set("sendmail_from","admin@localhost");
   $msg="hi.";
   $headers = "From:admin@localhost";   
   $to="john12@yahoo.com";
   if(mail($to,"Re info",$msg)){
   	echo "ok";
   }
?>
I using xampp.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Send mail at localhost

Post by califdon »

The PHP mail() function depends on there being a local mail server running. "For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file." (from w3schools.com) XAMPP doesn't include a mail server. Have you installed a mail server on your computer?
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: Send mail at localhost

Post by Live24x7 »

if you merely want to check if your mail functions are working properly or not,
try some server emulation tool which emulates smtp server on your localhost

I use:
http://www.toolheap.com/test-mail-server-tool/

It will not send mails but will dump copies of mail into .txt documents. You can read them like any other emails.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Send mail at localhost

Post by califdon »

Good tip, Live24x7! Thanks.
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: Send mail at localhost

Post by Live24x7 »

glad u found it useful. so far, i have only used this forum to get free help :)
GiaTuan
Forum Newbie
Posts: 14
Joined: Sat Oct 01, 2011 1:19 am

Re: Send mail at localhost

Post by GiaTuan »

Sometimes I get many of the same mail :dubious: .What happened?Can anyone explain?Have xampp limited time to send a mail?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Send mail at localhost

Post by califdon »

GiaTuan wrote:Sometimes I get many of the same mail :dubious: .What happened?Can anyone explain?Have xampp limited time to send a mail?
No, I would suggest that you check your script.
Post Reply