php邮件程序未发送邮件。代码中可能有错误吗?

php邮件程序未发送邮件。代码中可能有错误吗?,php,email,Php,Email,这是我想通过php发送电子邮件的代码。 这是我的代码,但邮件功能无法正常工作。它显示的错误是:Mailer error无法实例化邮件函数 <?php require_once('PHPMailer/class.phpmailer.php'); $frompage= $_REQUEST['frompage']; if($frompage=="contact"){

这是我想通过php发送电子邮件的代码。
这是我的代码,但邮件功能无法正常工作。它显示的错误是:Mailer error无法实例化邮件函数

    <?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 = "yogeshkamboj123@gmail.com"; //where email need to be sent
                $mail->AddAddress($address);
            //  $mail->AddCC("shweta.ohlyan@vermillion.net.in", "shweta.ohlyan@vermillion.net.in"); 

                $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!";
                }

            ?>


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

检查sendmail是否已启用,主要是当您的服务器由其他公司提供时

    <?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 = "yogeshkamboj123@gmail.com"; //where email need to be sent
                $mail->AddAddress($address);
            //  $mail->AddCC("shweta.ohlyan@vermillion.net.in", "shweta.ohlyan@vermillion.net.in"); 

                $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!";
                }

            ?>
上的PHPMailer帮助文档帮助我走上正确的道路


我发现
php.ini
没有定义
sendmail\u路径
,所以我添加了
sendmail\u路径=/usr/sbin/sendmail-t-I

1。您需要确保您的发件人地址是该服务器上设置的有效电子邮件帐户

2.确保还包括phpmailer附带的smtp类:

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

我希望这有帮助

我已经有一段时间没有看到ereg的行动了。5.3中没有折旧吗?