用PHP梅勒

问题描述:

由于邮件错误劝我一直在使用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> 

该错误是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