SystemOverload Posted September 16, 2009 Share Posted September 16, 2009 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 ------------------------------------------------------------------ } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.