2012-02-04 178 views
0

由於郵件錯誤勸我一直在使用PHP梅勒發送電子郵件附件的形式嘗試過,但我不斷收到錯誤消息「梅勒錯誤:無法實例化郵件功能用PHP梅勒

我已經重新檢查電子郵件地址找不到相同

這裏的錯誤是將PHP代碼以及窗體的任何代碼輸入,非常感謝感謝,JB

<html> 
<head> 
<title>PHPMailer - Mail() basic test</title> 
</head> 
<body> 

<?php 

require_once('class.phpmailer.php'); 

$mail    = new PHPMailer(); // defaults to using php "mail()" 

$body    = file_get_contents('talent3.html'); 
$body    = eregi_replace("[\]",'',$body); 

$mail->AddReplyTo("[email protected]","First Last"); 

$mail->SetFrom('[email protected]', 'First Last'); 

$mail->AddReplyTo("[email protected]","First Last"); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Beadle"); 

$mail->Subject = "PHPMailer Test Subject via mail(), basic"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //  optional, comment out and test 

$mail->MsgHTML($body); 

$mail->AddAttachment("images/phpmailer.pdf");  // attachment 
$mail->AddAttachment("images/phpmailer_mini.jpeg"); // attachment 

if(!$mail->Send()) { 
echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
echo "Message sent!"; 
} 

?> 

</body> 
</html> 

和表單代碼:。

<form action="test_mail_basic.php" method="post" 
enctype="multipart/form-data"> 
<label for="file" class="bodyCopy"><span class="bodyCopy">Attach resume:</span></label><br  /> 
<input type="file" name="attach1" id="file" /><br /> 
<br /> 
<label for="file" class="bodyCopy"><span class="bodyCopy">Attach photo:</span></label><br /> 
<input type="file" name="attach2" id="file" /><br /> 
<br /> 
<input type="submit" name="submit" value="Submit" /> 
</form> 

回答

1

該錯誤是php mail()函數返回false的結果。

通常,如果sendmail在php.ini中配置不正確,或者服務器上不存在sendmail,則返回false。

你在Linux服務器或Windows上運行這個嗎?看到一個非常簡單的測試,如果郵件的工作是運行這段代碼:

<?php 
$to = '[email protected]'; 

$res = mail($to, 'Testing mail', "This is a test\n\nEnd.", "From: $to"); 

if ($res) { 
    echo "Message appears to have been accepted"; // does not mean it will be delivered 
} else { 
    echo "PHP mail() failed."; 
} 

如果您使用的是Windows,你可能會需要使用SMTP服務器,而不是PHP的mail(),所以你需要使用如在此phpmailer SMTP example中看到的SMTP。

如果您使用的是共享主機,可能是由於某些額外參數被髮送到郵件功能而導致郵件被拒絕。

+0

我在Linux上(我想)如何「運行」代碼? – 2012-02-04 20:34:16

+0

你使用裏面的這段代碼創建一個文件,並在本地主機上運行它。您需要安裝apache,php和postfix/exim才能正常工作 – Alex 2012-02-04 20:38:37

+0

是否將代碼保存爲.php文件或.html文件?另外,我該如何運行 - 我仍然不明白這一部分。通過運行,你的意思是上傳到服務器,然後在瀏覽器中打開它? – 2012-02-04 20:47:14