2017-10-11 89 views
-1

这里是我的代码,我想通过PHP发送电子邮件。
这是我的代码,但邮件功能无法正常工作。它显示错误:邮件程序错误无法实例化邮件功能。php邮件不发送邮件。代码中可能有错误?

<?php 
       require_once('PHPMailer/class.phpmailer.php'); 
        $frompage= $_REQUEST['frompage']; 
      if($frompage=="contact"){  
        $mname= $_REQUEST['mname']; 
        $mmobile= $_REQUEST['mmobile']; 
        $memail= $_REQUEST['memail']; 
        $gemail= str_replace("atsymbol","@",$memail); 
        $mcomment= $_REQUEST['mcomment']; 
        $body = file_get_contents('email-template.html'); 

        $body = eregi_replace("<mfrompage>" , $frompage, $body);  
        $body = eregi_replace("<mname>" , $mname, $body); 
        $body = eregi_replace("<mmobile>" , $mmobile, $body);    
        $body = eregi_replace("<memail>" , $gemail, $body);  
        $body = eregi_replace("<mcomment>" , $mcomment, $body); 
      } 
      if($frompage=="career"){   
        $mname= $_REQUEST['mname']; 
        $mmobile= $_REQUEST['mmobile']; 
        $memail= $_REQUEST['memail']; 
        $gemail= str_replace("atsymbol","@",$memail); 
        $mcomment= $_REQUEST['mcomment']; 
        $body = file_get_contents('email-template2.html'); 

        $body = eregi_replace("<mfrompage>" , $frompage, $body);  
        $body = eregi_replace("<mname>" , $mname, $body); 
        $body = eregi_replace("<mmobile>" , $mmobile, $body);    
        $body = eregi_replace("<memail>" , $gemail, $body);  
        $body = eregi_replace("<mcomment>" , $mcomment, $body); 
      } 


       $mail = new PHPMailer(); // defaults to using php "mail()" 
       $mail->AddReplyTo($gemail,$mname); 
       $mail->SetFrom($gemail,$mname); 
       $address = "[email protected]"; //where email need to be sent 
       $mail->AddAddress($address); 
      // $mail->AddCC("[email protected]", "[email protected]"); 

       $mail->Subject = "Query from website Vermillion.net.in"; 
       //$mail->AltBody = "This is for text based email"; // optional 
       //$mail->Body=$body; 
       $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 sucessfully!"; 
       } 

      ?> 

这是我的代码,但邮件功能无法正常工作。它显示错误:邮件程序错误无法实例化邮件功能。

+0

它已经有一段时间在香港专业教育学院看到行动'ereg'。在5.3中没有贬值吗? –

回答

0

检查sendmail是否启用,主要是如果您的服务器是由其他公司提供的。

PHPMailer帮助文档this specific error帮助我找到了正确的道路。

我发现那是什么php.ini没有了sendmail_path定义,所以我补充说,sendmail_path = /usr/sbin/sendmail -t -i;

1

1.You需要确保从地址你是服务器上的一个有效的电子邮件帐户设置。

2.确保您还包括带有PHPMailer的SMTP类:

// for mailing 
require("phpmailer/class.phpmailer.php"); 
require("phpmailer/class.smtp.php"); 
require 'phpmailer/PHPMailerAutoload.php'; 

我希望它能帮助