phpmailer error Could not instantiate mail function

0 votes

I'm getting the error "Mailer Error: Could not instantiate mail function" when I use the mail() basic example modified slightly for my user id.

When I use the mail function -

mail($to, $subject, $message, $headers);

It works fine, though I'm having trouble sending HTML, which is why I'm trying PHPMailer.

The code:

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

Can someone please help me with this?

Jun 13, 2022 in PHP by narikkadan
• 63,700 points
2,149 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Error: Global Variable is not accessable to local function

Hey kartik, A variable declared outside a function has a ...READ MORE

answered Feb 19, 2020 in PHP by Niroj
• 82,880 points
865 views
0 votes
1 answer

Error:PDOException could not find driver

Hello @kartik, You need to have a module ...READ MORE

answered Sep 14, 2020 in PHP by Niroj
• 82,880 points
13,663 views
0 votes
1 answer

error: Class 'PHPUnit_Framework_TestCase' not found in …?

Hello,  You can use TestCase instead PHPUnit_Framework_TestCase // use the following namespace use ...READ MORE

answered Apr 20, 2020 in PHP by Niroj
• 82,880 points
4,165 views
0 votes
1 answer

Error:WP_Query() does not return all entries

Hello, Try adding posts_per_page=-1 to the string of parameters passed ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,880 points
864 views
0 votes
1 answer

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in .?

Hello @kartik, You may get this error because ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,880 points
2,098 views
0 votes
1 answer
0 votes
0 answers

PHPMailer: SMTP Error: Could not connect to SMTP host

I am having trouble sending mail through ...READ MORE

May 8, 2022 in PHP by Kichu
• 19,050 points
2,875 views
0 votes
0 answers

Mailer Error: SMTP connect() failed in php mailer( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting)

Here is code for sending email from ...READ MORE

Jun 2, 2022 in PHP by Kichu
• 19,050 points
12,220 views
0 votes
1 answer

SMTP connect() failed PHPmailer - PHP

 You need to add the Host parameter $mail->Host ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
4,086 views
0 votes
0 answers

"SMTP Error: Could not authenticate" in PHPMailer

I want to send emails in Gmail ...READ MORE

May 7, 2022 in PHP by narikkadan
• 63,700 points
4,236 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP