我在bluehost服务器上运行以下代码。 mail()函数发送电子邮件但不返回任何值

时间:2013-02-19 11:53:53

标签: php html5

 <?php 
 $m = ""; 
 $to = "anymail@gmail.com";                     
 $from = "anymail@mydomainname.com";
 $subject = 'subject';
 $message = "Any Message";
 $headers = "From: $from\n"; 
 $headers .= "MIME-Version: 1.0\n"; 
 $headers .= "Content-type:text/html; charset=iso-8859-1\n";
 if ( mail($to, $subject, $message, $headers) ) { 
     $m = "Email sent successfully"; exit(); 
 }else { 
     $m = "Email can't be sent.";exit();
 }  
 exit(); 
 ?>
 <!DOCTYPE HTML><html>
 <head><meta charset="utf-8"><title>Untitled Document</title></head>
 <body>
 <h2> 
 <?php  
   echo $m; 
 ?> </h2>
 </body></html> 

我无法得到确认。有谁可以指出这个问题?

1 个答案:

答案 0 :(得分:0)

使用此代码,exit()停止执行而不打印$m

的值
if ( mail($to, $subject, $message, $headers) ) { 
   $m = "Email sent successfully"; 
   //exit(); 
}else { 
   $m = "Email can't be sent.";
   //exit();
}  
//exit();