Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpmailer error "Could not instantiate mail function"

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

if 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.

this is 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("[email protected]","my name");     $mail->SetFrom('[email protected]', 'my name');     $address = "[email protected]";     $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!";     } ?> 
like image 777
sdfor Avatar asked Aug 18 '09 23:08

sdfor


People also ask

What is SMTP in PHPMailer?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.

Could not be sent mailer error SMTP connect () failed?

SMTP connect() failed. then, this is mostly because of the firewall rules on their infrastructure which explicitly blocks the outgoing SMTP connection to ports 25, 587 and 465 to all external servers.


2 Answers

Try using SMTP to send email:-

$mail->IsSMTP(); $mail->Host = "smtp.example.com";  // optional // used only when SMTP requires authentication   $mail->SMTPAuth = true; $mail->Username = 'smtp_username'; $mail->Password = 'smtp_password'; 
like image 62
Mukesh Chapagain Avatar answered Sep 24 '22 16:09

Mukesh Chapagain


Your code looks good, did you forget to install PostFix on your server?

sudo apt-get install postfix 

It worked for me ;)

Cheers

like image 44
Irwuin Avatar answered Sep 25 '22 16:09

Irwuin