Jump to content

Recommended Posts

Hey

 

I'm on PHP 5.3.4ish.  I've recently started using PHPMailer, but when testing it, end up with an "Could not instantiate mail function." error.

 

Does anyone have any ideas?

 

My files are laid out as below:

 

/emailtest.php

- Calls fn_mailer("test@live.co.uk","Test Email Recipient","Subject","BODY")

/includes/functions/fn_comms.php

- Contains function fn_mailer(), a simple wrapper that accesses the PHPMailer Functionality...

/includes/functions/phpmailer/class.phpmailer.php

/includes/functions/phpmailer/class.pop3.php

/includes/functions/phpmailer/class.smtp.php

 

fn_mailer()

function fnMailer ($varToEmail, $varToName, $varSubject, $varBody) {
// - -- --- Wrapper for PHP Mailer Class Interface ------------------------------------
require_once 'phpmailer/class.phpmailer.php';

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

try {
  $mail->AddReplyTo('support@test.info', 'Support');
  $mail->AddAddress($varToEmail, $varToName);
  $mail->SetFrom('donotreply@test.info', 'Admin');
  $mail->Subject = $varSubject;
  $mail->AltBody = 'To view this email message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  //$mail->MsgHTML(file_get_contents('contents.html'));
  $mail->MsgHTML($varBody);
  //$mail->AddAttachment('images/phpmailer.gif');      // attachment
  //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
          echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
// - -- --- END OF WRAPPER ------------------------------------------------------------------
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.