-1

here is my code i want to ssend email through php.
this is my code but mail function is not working properly. and it is showing error of : Mailer error could not instantiate mail function.

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

            ?>

this is my code but mail function is not working properly. and it is showing error of : Mailer error could not instantiate mail function.

yogesh
  • 11
  • 4

2 Answers2

1

1.You need to make sure that your from address is a valid email account setup on that server.

2.Make sure that you also include smtp class which comes with phpmailer:

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

I hope it helps

0

Check if sendmail is enabled, mostly if your server is provided by another company.

The PHPMailer help docs on this specific error helped to get me on the right path.

What I found is that php.ini did not have the sendmail_path defined, so I added that with sendmail_path = /usr/sbin/sendmail -t -i;

Toastrackenigma
  • 7,604
  • 4
  • 45
  • 55