Reputation: 4164
<?php
//define the receiver of the email
$to = '[email protected]';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: [email protected]\r\nReply-To: [email protected]";
//send the email
$mail_sent = mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";
?>
i am using xampp for windows can you help me to configure smtp server.....
output is
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 D:\installed\xampp\htdocs\mail.php on line 13 Mail failed
Upvotes: 0
Views: 2235
Reputation: 574
PHP mail() needs a mail relay server to actually send mail. On hosting providers, the enviroment is preconfigured and ready for use.
These are the possible solutions for you.
Upvotes: 1
Reputation: 3792
try removing "@". I have tried this sample code, in which I am fetching data from input form. there is one more method, using SMTP, if you know the SMTP server credentials you can use that way either. Here is the sample;
Upvotes: 1
Reputation: 14433
It depends a lot of the environment, like my where my site is hosted I guess mail function is disabled and does not work. So, I use SMTP and use google mail service for corporate.
Upvotes: -1
Reputation: 13488
Make sure your sendmail settings are correct in your php.ini
file. Assuming you're running *nix:
SMTP = myserver.localnet.com
sendmail_from = [email protected]
sendmail_path = /usr/sbin/sendmail
There are a few 'gotcha's with mail(). See this StackOverflow post for more information.
Upvotes: 0