据我所知,我已尝试使用PHP Mailer发送带有表单的电子邮件附件,但是我不断收到错误消息“Mailer Error:无法实例化邮件功能。
我已经重新检查了电子邮件地址,但找不到相同的错误
这里是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("jbgraphics@rogers.com","First Last");
$mail->SetFrom('jbgraphics@rogers.com', 'First Last');
$mail->AddReplyTo("jbgraphics@rogers.com","First Last");
$address = "jbgraphics@rogers.com";
$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>
答案 0 :(得分:1)
该错误是php mail()函数返回false的结果。
通常,如果在php.ini中未正确配置sendmail或者服务器上不存在sendmail,则返回false。
您是在Linux服务器或Windows上运行吗?查看邮件是否正常工作的一个非常简单的测试是运行此代码:
<?php
$to = 'you@yoursite.com';
$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(),因此您需要使用SMTP,如phpmailer SMTP example所示。
如果您在共享主机上,可能是因为某些额外参数被发送到邮件功能而拒绝邮件。