phpmailer错误“无法实例化邮件功能” [英] phpmailer error "Could not instantiate mail function"
本文介绍了phpmailer错误“无法实例化邮件功能”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 mail()
基本示例略微修改了我的用户ID,我收到错误Mailer错误:无法实例化邮件功能
I'm using the mail()
basic example modified slightly for my user id and I'm getting the error "Mailer Error: Could not instantiate mail function"
如果我使用邮件功能 -
if I use the mail function -
mail($to, $subject, $message, $headers);
它工作正常,虽然我无法发送html,这就是为什么我正在尝试PHPMailer
it works fine, though I'm having trouble sending html, which is why I'm trying PHPMailer.
这是代码:
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
print ($body ); // to verify that I got the html
$mail->AddReplyTo("reply@domain.com","my name");
$mail->SetFrom('from@domain.com', 'my name');
$address = "to@domain.com";
$mail->AddAddress($address, "her name");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
推荐答案
尝试使用 SMTP 发送电子邮件: -
Try using SMTP to send email:-
$mail->IsSMTP();
$mail->Host = "smtp.example.com";
// optional
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';
这篇关于phpmailer错误“无法实例化邮件功能”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文