2012-02-15 163 views
0

我試圖從PHP發送郵件,但它不工作。即使是最後一封電子郵件也沒有空白郵件。建議嗎?PHP郵件不發送郵件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Smart Gardens Gravesend | Garden Maintenance</title> 
<link href="global.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" media="all" type="text/css" href="menu_style.css" /> 
     <link rel="stylesheet" href="engine/css/vlightbox.css" type="text/css" /> 
     <style type="text/css">#vlightbox a#vlb{display:none}</style> 
     <link rel="stylesheet" href="engine/css/visuallightbox.css" type="text/css" media="screen" /> 
     <script src="engine/js/jquery.min.js" type="text/javascript"></script> 
</head> 
<body> 
<div id="wrapper"> 
<div id="logo2"><img src="images/logo_02.png" width="231" height="101" alt="logo" /></div> 
<div class="menu bubplastic horizontal lime"> 
    <ul> 
     <li><span class="menu_r"><a href="about.html"><span class="menu_ar">About Us</span></a></span></li> 
     <li class="highlight"><span class="menu_r"><a href="maintenance.html"><span class="menu_ar">Maintenance</span></a></span></li> 
     <li><span class="menu_r"><a href="landscaping.html"><span class="menu_ar">Landscaping</span></a></span></li> 
     <li><span class="menu_r"><a href="tree.html"><span class="menu_ar">Tree Work</span></a></span></li> 
     <li><span class="menu_r"><a href="fencing.html"><span class="menu_ar">Fencing</span></a></span></li> 
     <li><span class="menu_r"><a href="contact.php"><span class="menu_ar">Contact Us</a></span> 
     </div> 
<div id="content"> 
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> 
<table border ="0"> 
<tr> 
    <td width="133">Name:</td><td width="252"><input type="text" size="42" name="name"/></td></tr> 
<tr> 
    <td>Email:</td><td><input type="text" name="email" size="42"/></td></tr> 
<tr><td>Message</td><td><textarea name="message" rows="5" cols="31"></textarea></td></tr> 
<tr><td></td><td><input type="submit" value="Submit"/></td></tr> 
</table> 
</form> 
<?php 
if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])){ 
$name = $_REQUEST['name'] ; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ; 
$headers = "X-Mailer: php"; 
mail("[email protected]", "Email from $name", 
$message, "From:" . $email, $headers); 
echo "Thanks, your email has been sent!"; 
} 
?> 
<br /> 
<br /> 
<div class="commentbox"> 
<h2>Caroline Roe, Old Road East, Gravesend</h2> 
<p>Smart Gardens have been maintaining our gardens for 4 years now. We are very happy with their personal, friendly and knowledgable service. Highly recommended.</p> 
</div> 
<div class="commentfooter"></div> 
<div class="commentbox"> 
<h2>Brian Colley, Darnley Road, Gravesend</h2> 
<p>The Smart Gardens Team have been caring for our gardens for a number of years . Their conscientious, reliable work demonstrates the strength of their professional knowledge and versatile ability.</p> 
<p>They have been able to make worthwhile, constructive suggestions which have led to the development and maturity of the rear garden particularly, in both the hard and soft landscape areas.</p> 
<p>Their helpful, friendly and trustworthy nature is second to none and we heartily recommend them for routine maintenance or major project development work.</p> 
</div> 
<div class="commentfooter"></div> 
<div class="commentbox"> 
<h2>Mrs Hathrill, Windmill Hill, Gravesend</h2> 
<p>I have regularly used the services of Smart Gardens for both Maintenance and Landscape projects.</p> 
<p>They are conscientious, hard working and always strive for perfection. They are also friendly and approachable. I would not hesitate to recommend them.</p> 
</div> 
<div class="commentfooter"></div> 
</div> 
</body> 
</html> 

同樣的PHP代碼已在其他郵件程序的工作,但不知道爲什麼這一個不工作:\感謝!

+0

你使用免費託管? – Cheery 2012-02-15 01:44:57

+0

是的,我怎麼回事?不應該影響它,因爲我在同一主機上託管其他郵件程序網站 – 2012-02-15 01:46:39

+1

免費託管通常會禁用傳出連接和郵件功能以防止濫用。 – Cheery 2012-02-15 01:48:03

回答

2

您很可能在電子郵件服務器上遇到問題。

但是,下面的代碼似乎不正確。

mail("[email protected]", "Email from $name", 
$message, "From:" . $email, $headers); 

嘗試:

$headers = "From:" . $email . "\r\n"; 
$headers .= "X-Mailer: php\r\n"; 
mail("[email protected]", "Email from $name", 
$message, $headers); 

還要注意,設置「發件人」地址到一個不屬於你的域名可能會導致該消息在某個時候被阻塞(無論是你的主機或收件人的垃圾郵件過濾器)。 您可能需要設置一個Reply-To:標題,並簡單地使用From:作爲屬於您的服務器的電子郵件地址。