Page 1 of 1

Quick question on email function [SOLVED]

PostPosted: Wed Apr 28, 2010 7:09 pm
by jhenry
Quick question on the email functions. I setup an afterInsert as per the Triggers Wiki using the following code:

Code: Select all
function afterInsert(&$record){
      /**
     * Trigger that is called after Course record is inserted.
     * @param $record Dataface_Record object that has just been inserted.
     */


   $response =& Dataface_Application::getResponse();
        // get reference to response array

    if ( mail('jason@mail.com', 'Record Update-Infinity', 'A Workorder has been entered.') ){
        $response['--msg'] .= "\nEmail sent to jason@mail.com successfully.";
    } else {
        $response['--msg'] .= "\nMail could not be sent at this time.";
    }
}


I only get the Mail could not be sent at this time message. Is this automatically accessible or do I have to load the email module?

TIA

Jason

Re: Quick question on email function

PostPosted: Thu Apr 29, 2010 8:45 am
by tomhousley
Hi Jason,

I use the following to send emails for afterUpdate function, but the same principle applies.

Code: Select all
$to      = 'FirstName LastName <name@email.com>';
$subject = 'Email Subject';
$message = 'Email Message';
$headers = 'FirstName LastName <name@email.com>' . "\r\n" .
   'Reply-To: name@email.com';
   
//php mail function//
mail($to, $subject, $message, $headers);


More information on the php mail function here: http://php.net/manual/en/function.mail.php

All the best, Tom

Re: Quick question on email function

PostPosted: Thu Apr 29, 2010 2:33 pm
by jhenry
Thanks for the response Tom that looks much simpler and cleaner to maintain. Is there any other setup as far as sendmail or do I need to set up the email module in dataface to make this work or is the functionality all handled by php?

TIA,
Jason

Re: Quick question on email function

PostPosted: Fri Apr 30, 2010 4:24 am
by tomhousley
Hi Jason,

As far as I'm aware it's all handled by PHP.

I used shared hosting for my xataface applications and it works out of the box - so to speak. I don't have the email module installed.

All the best, Tom

Re: Quick question on email function

PostPosted: Fri Apr 30, 2010 6:18 pm
by jhenry
Thanks for the assistance Tom I checked my php logs and saw where I was getting errors saying I did not have sendmail installed. I installed it and it looks like it is working. If I am not mistaken most ISPs like you host yours on have that for webmail. Or at least some type of mail transport agent. I should have known. Thanks again.

Jason