Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Could not instantiate mail function

edited August 2012 in Vanilla 2.0 - 2.8

This error has been troubling me for a while since I can not replicate it outside of Vanilla. My current setup:

  • Not using an SMTP server
  • name of the sender is specified
  • email of the sender is specified

When attempting to send an email Vanilla will always complain it Can not instantiate the mail function. I have checked I can send emails through the mail function on the command line with the following script and it works as expected.

<?php
$to = "grandwazir@x.net";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "grandwazir@x.net";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 

I am at a loss what to try next given that with debugging on I am getting nothing useful out of Vanilla about why the error is occuring.

Comments

  • in your test program replace the last lines with this and report the results you get.

    try this - what do you get.

    <?php
    $to = "grandwazir@x.net";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "grandwazir@x.net";
    $headers = "From:" . $from;
    $rt = @mail($to,$subject,$message,$headers);
    if ($rt) {
          echo  "mail was successfully accepted for delivery"
          } else {
           echo "Could not instantiate mail function." 
           }
    ?> 
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited August 2012

    mail was successfully accepted for delivery, together with the email in my mailbox.

  • peregrineperegrine MVP
    edited August 2012

    well the php mailer program does this

    /library/vendors/phpmailer/class.phpmailer.php

    in line 687/

      if(!$rt) {
          throw new phpmailerException($this->Lang('instantiate'), self::STOP_CRITICAL);
        }
    

    just for grins you could change the error message in line 857

    'instantiate' => 'Could not instantiate mail function.',

    to

    'instantiate' => 'my test - Could not instantiate mail function.',

    and see if this is where the message is coming from.

    if that is the case - you could always comment out the throw statement.

    the question is why does it return a FALSE in vanilla and a true in the test program. -

    some ideas -
    you could echo and dump some variables to debug and may be related to ini_settings - don't know. or quantity of mail going out.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I appear to have found the problem. Vanilla appears to not be specifiying a To address when sending emails for some reason:

    PHP message: to: 
    PHP message: from: Password Reset
    PHP message: body: Hello <hidden>!
    
    grandwazir has reset your password at x. Your login credentials are now:
    
    Email: noreply@x.net
    Password: x
    Url: http://forum.x.net/
    
    Have a great day!
    
    PHP message: headers: Date: Tue, 28 Aug 2012 13:49:59 -0400
    Return-Path: grandwazir@x.net
    From: grandwazir <grandwazir@x.net>
    Message-ID: <125bd1d48e765cc7d46b394d0406394a@forum.x.net>
    X-Priority: 3
    X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/plain; charset="utf-8"
    

    I now need to find out why.

  • Having changed that message, the error is coming from that part of the library. I did echo the variables earlier but the post was marked for moderation for some reason. I'll try again.

    to: noreply@x.net

    subject: [x] Password Reset

    message:

    Hello Bladeruk!
    
     grandwazir has reset your password at x. Your login credentials are now:
    
     Email: noreply@x.net
     Password: Uj6827W
    
     Have a great day!
    

    headers:

    Date: Tue, 28 Aug 2012 14:10:53 -0400
    Return-Path: grandwazir@x.net
    From: grandwazir <grandwazir@x.net>
    Message-ID: <de224ea30706dd8b4a1df4e24536c40a@forum.x.net>
    X-Priority: 3
    X-Mailer: PHPMailer 5.1 (phpmailer.sourceforge.net)
    MIME-Version: 1.0
    Content-Transfer-Encoding: 8bit
    Content-Type: text/plain; charset="utf-8"
    
  • I would post the results of the variable echos but every time I do so my comment is marked for moderation which is rather frustrating. In summary though it is setting everything correctly. The only major difference is phpmailer sets more headers than the test message does.

  • Thinking about it, Vanilla is setting a different domain in the MessageId field that the test program. Prehaps that could be the problem?

  • peregrineperegrine MVP
    edited August 2012

    look at line 657 vs 671 vs 678 - which one does not have the correct header info.
    try logging the header for various messages and combos.

    is the $toArr set correctly or does it possibly have a null.
    same with $to.

    also some other issues here
    http://www.php.net/manual/en/function.mail.php

    good luck and post your resolution for others.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • The array is set correctly as I can get the to address from it when I set error logging in the loop just after 656. It is sending the message from that loop not the others. It is not that the header is incorrect, it is just different from the test script.

    The test script uses the hostname of the machine as if you were to do a lookup while the other one is set to the url of the vanilla forum. I am going to try adding that header to the test script and see if that breaks it.

  • peregrineperegrine MVP
    edited August 2012

    can you post what you statements you added for error logging to a file It would be useful to have that as an example here.

    $val is correct. correct? in 658?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • It appears that running the test script as the same user as the webserver reveals the following errors:

    2012-08-28 20:55:45 1T6Rt3-0005nc-8D Failed to create spool file /var/spool/exim4/input//1T6Rt3-0005nc-8D-D: Permission denied
    2012-08-28 20:55:45 1T6Rt3-0005nc-8D Failed to create spool file /var/spool/exim4/input//1T6Rt3-0005nc-   8D-D: Permission denied
    2012-08-28 20:55:45 1T6Rt3-0005nc-8D Failed to create spool file /var/spool/exim4/input//1T6Rt3-0005nc-8D-D: Permission denied
    Could not instantiate mail function.
    

    I have now discovered why this is happening. Exim is set to use Setuid when called. When I reorganised the partitions on the server I disabled setuid for the /usr partition breaking exim.

    Adding setuid back to the mount options of the partition fixed the issue.

  • peregrineperegrine MVP
    edited August 2012

    @grandwazir

    good deal.

    can you post what your coding statements were when you set error logging in the loop in /library/vendors/phpmailer/class.phpmailer.php. If you want to reciprocate.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.