Using php mailer

Discussion in 'PHP' started by look4guna, Dec 18, 2010.

  1. #1
    Hi friends,

    i tried to send a mail using phpmailer class, but it throws an error "Mailer Error: Could not instantiate mail function."
    so i thought to use mail() function of php but i got a blank page. so what is the actual problem?

    this is code i used:
    <?php
    require("classes/class.phpmailer.php");

    $mail = new PHPMailer(); // defaults to using php "mail()"

    //$body = file_get_contents('contents.html');
    //$body = eregi_replace("[\]",'',$body);
    $body="its working hio!";

    $mail->AddReplyTo("look4guna@hiox.com","First Last");

    $mail->SetFrom('look4guna@hiox.com', 'First Last');

    $mail->AddReplyTo("look4guna@hiox.com","First Last");

    $address = "guna@hiox.com";
    $mail->AddAddress($address, "GunaVK");

    $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.gif"); // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

    if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
    echo "Message sent!";
    }

    ?>

    can anybody get me out of this problem? Thanks:)
     
    look4guna, Dec 18, 2010 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    Are you running it locally or on a server ?
    Locally it doesn't work for me either , because it can't deliver the email using mail()... Thats why it throws that error.

    Here's my code.
    
    <?php
        require("classes/class.phpmailer.php");
        $mail = new PHPMailer();
        
        $bodyHTML = "<h1>Its working hio!</h1>";
        $bodyTXT = "Its working hio!";
        
        $mail->SetFrom('look4guna@hiox.com', 'First Last',1);
        $mail->AddAddress("guna@hiox.com", "GunaVK");
        $mail->Subject = "PHPMailer Test Subject via mail(), basic";
        $mail->Body = $bodyHTML;
        $mail->AltBody = $bodyTXT;
        $mail->isHTML(true);
        
        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message sent!";
        }
    ?>
    
    PHP:
     
    tvoodoo, Dec 18, 2010 IP
  3. look4guna

    look4guna Active Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    I think you're right tvoodoo. I tried to run it locally. I didn't that much about mail related concepts, so the same will run if we put it into a server ah? do we need any permissions from the hosting company to send mails?
     
    look4guna, Dec 18, 2010 IP
  4. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #4
    No need for any special permissions
     
    tvoodoo, Dec 18, 2010 IP
  5. MyEasyCpa

    MyEasyCpa Peon

    Messages:
    336
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What server bein run on?
     
    MyEasyCpa, Dec 18, 2010 IP
  6. look4guna

    look4guna Active Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    it is apache..
     
    look4guna, Dec 20, 2010 IP