2013-03-05 91 views
-1

我有一個利用PHP Mail()函數的HTML表單。我使用的SMTP服務器是localhost,不需要驗證。PHP不會發送HTML郵件

<form action="../../Scripts/fused.php" method="POST"><p>Name</p> <input type="text" name="name"> 
<p>Email</p> <input type="text" name="email"> 
<p>Phone</p> <input type="text" name="phone"> 

<p>Request Phone Call:</p> 
Yes:<input type="checkbox" value="Yes" name="call"><br /> 
No:<input type="checkbox" value="No" name="call"><br /> 

<p>Website</p> <input type="text" name="website"> 

<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /> 
<input type="submit" value="Send"><input type="reset" value="Clear"> 
</form> 

這裏是php文件:

<?php 

$name = $_POST['name']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$call = $_POST['call']; 
$website = $_POST['website']; 
$message = $_POST['message']; 
$formcontent = 'From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Message: $message'; 
$recipient = '[email protected]'; 
$subject = 'Fused Enterprises Contact Form'; 

$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n"; 
$headers .= 'Cc: [email protected]' . "\r\n"; 

mail($recipient, $subject, $formcontent, $headers) or die("Error!"); 

echo "Thank You, the form has been submitted. Someone from the Team will contact you shortly." . " -" . "<a href='/Home/' style='text-decoration:none; color:#1e90ff;'> Return Home</a>"; 

?> 

我一定要實現PEAR郵件?我也試圖實現,並且我沒有收到電子郵件。我不知道它是否失敗。腳本運行,我得到echo,但我從來沒有收到電子郵件。它沒有去垃圾郵件文件夾。

該網站託管(與此腳本一起)在example.com下,但電子郵件使用本地主機與smtp服務器mail.example.com。它們託管在同一臺服務器上。域名的差異可能是一個問題?

+0

當你說「不會發送」你的意思是它給人的錯誤,或者您沒有收到該電子郵件?你有檢查過你的垃圾郵件文件夾嗎? – 2013-03-05 19:40:17

+0

我沒有收到電子郵件。我沒有任何跡象表明它是否失敗。我也檢查過垃圾郵件文件夾,但它會發送兩封不同的電子郵件,但都未收到。 – user1453549 2013-03-05 19:51:07

+0

檢查您的郵件日誌。 – Sammitch 2013-03-05 21:11:28

回答

0

某些主機關閉了其服務器發送電子郵件的功能(因此無法從其服務器發送垃圾郵件)。我會首先檢查。

+0

我檢查了主機,他們說我可以用它來發送郵件,沒有驗證,並且我將不得不使用'localhost'作爲SMTP服務器(不是mail.example.com),我無法弄清楚如何在上面的示例中成功實現代碼以識別該服務器。 – user1453549 2013-03-05 19:58:59

1

要以HTMl格式發送郵件,標題是最重要的。 使用此PHP函數.. 我在這裏使用這個腳本... http://ieeeaset.com/mailer/mailer.php

function htmlmail() 
    { 
     if (strtoupper(substr(PHP_OS,0,3)=='WIN')) { 
      $eol="\r\n"; 
     } elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) { 
      $eol="\r"; 
     } else { 
      $eol="\n"; 
     } 
     $recmail = $_POST['toemail']; // address where you want the mail to be send 
     $sub = $_POST['subject']; //subject of email that is sent 
     $mess = $_POST['message']; 
     $pattern[0]="\'"; 
     $pattern[1]='\"'; 
     $replace[0]="'"; 
     $replace[1]='"'; 
     $mess= str_replace($pattern, $replace, $mess); 
     $headers = "From: [senders_email].$eol . 
     "MIME-Version: 1.0".$eol . 
     "Content-type: text/html; charset=iso-8859-1"; 
      mail($recmail,$sub,$mess,$headers); 
    }