Phpmailer: Could not instantiate mail function

i’m having a problem sending an email using phpmailer…
The error is:

Message was not sent
Mailer Error: Could not instantiate mail function.

heres the code:

<?php
require("phpmailer-1.73/phpmailer/class.phpmailer.php");
$mail = new PHPMailer(); //instantiate

$mail->From     = "deca@platform.com";
$mail->FromName = "DECA";
$mail->AddAddress("popendot@yahoo.com","Dhruv G");
$mail->AddReplyTo("info@platform.com","Information");

$mail->WordWrap = 50;                              // set word wrap
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Test";
$mail->Body     =  "Body Testing...";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?> 

IMO experience this is caused my errenous configuration of php.ini
Are you on a windows server? Have you setup your php.ini to send email?

You could also try a test email with the standard mail function to see if that works:


  if(mail('test@domain.com', 'Test email', 'Test email with standard mail() function')) {
  echo 'Mail sent';
 }
  else echo 'Mail sending failed';
  

I presume you have the sendmail set up. For the version I have running on a Linux server I also have this line

$mail->IsMAIL();

whereas if using SMTP you would have

$mail->IsSMTP();

put either one of these lines in after instantiating the class

i added the line…it still doesnt work
i’m thinking it’s probably my php.ini file, here is the only change i’ve made to it SINCE i’ve installed phpmailer: (NOTE: I’M TESTING MY LOCAL FILES ON APACHE)

[B][mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = root@localhost.com[/B]

I presume when you say Local Files on Apache you mean locally on your own machine and not on a hosted server? If so unless you have an SMTP server running then I can’t see that working. Change the SMTP from localhost to your SMTP address of your ISP. Also if you’re using SMTP email then you need the second line I mentioned earlier, the IsSMTP() line, plus you also need to include the SMTP class in the same directory as your phpmailer class.

ok, so i am not using SMTP any more…i’ve switched to MAIL
I’ve changed the code to the following…

require("phpmailer-1.73/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsMAIL(); 

and since im not using smtp, i’ve not made the changes in the php.ini file

php.ini:

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = me@localhost.com

IT STILL DOESNT WORK! – SAME ERROR!

Putting SMTP won’t work unless you have a mail server setup on your localhost.

An excerpt of my php.ini:


 [mail function]
 ; For Win32 only.
 SMTP = mail.tpg.com.au
 smtp_port = 25
 
 ; For Win32 only.
 sendmail_from = myusername@tpg.com.au
 

tpg is my ISP and I connect to their mail server using my username. This is why there is a lag when your local PHP scrips send email, because they take a little longer to connect to the ISPs server.

and then use the IsSMTP() function because this is what you’re using, an SMTP server instead of *nix Sendmail. ie. have for your PHP

require("phpmailer-1.73/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); 

and use cranial-bore’s excerpt above, changing the SMTP address to the SMTP address that your mail program such as Outlook uses. If you don’t use a from address then the sendmail_from address should be filled in (to be honest it’s best for safety anyhow), again use your own email address.

then in theory it should work providing your ISP will allow the email to go through in this manor (as some may bounce it back).