开发者

php mail function..... Iam getting output as "mail failed". can you please help me to get it done

开发者 https://www.devze.com 2022-12-13 04:36 出处:网络
<?php //define the receiver of the email $to = \'pradz39@gmail.com\'; //define the subject of the email
<?php
//define the receiver of the email
$to = 'pradz39@gmail.com';
//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: webmaster@example.com\r\nReply-To: webmaster@example.com";
//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


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.

  • In your case you must check if your xampp bundle comes with a mail server and setup/start it
  • If it doesn't come with a mail server, then you need to either setup your IIS SMTP server instructions at http://support.microsoft.com/kb/230235
  • Or download and install a free smpt server like Argosoft
  • You can also use a php package that can directly connect to SMTP with authentication support and use your real smpt server (hotmail, yahoo etc, isp) for relaying. This can be done with PHPMailer and it worked for me too.


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;


Make sure your sendmail settings are correct in your php.ini file. Assuming you're running *nix:

SMTP = myserver.localnet.com   
sendmail_from = me@localhost.com  
sendmail_path = /usr/sbin/sendmail

There are a few 'gotcha's with mail(). See this StackOverflow post for more information.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消