tags:

views:

272

answers:

4

I'm trying to sends mails in PHP. The code I used for sending a mail in CakePHP is given below. I get the message 'Simple Email Sent' in my web page but the mail is not delivered to my inbox. Am I missing something?

The values in the to, subject and link fields are set with the values entered in the user interface.

    $this->set('to',$this->params['form']['to']);
    $this->set('subject',$this->params['form']['subject']);
    $this->set('link',$this->params['form']['link']);
    $this->Email->to      = to;
    $this->Email->subject = subject;
    $this->Email->from    = '[email protected]';
    $this->Email->delivery= 'mail';
    $this->Email->sendAs='text';
    $this->Email->template = 'simple_message';
    //$this->Email->send(link);
    if ( $this->Email->send(link) ) {

        $this->Session->setFlash('Simple email sent');
    } else {
        $this->Session->setFlash('Simple email not sent');
    }
A: 

Are you sending this mail from localhost or a webserver?

FrankBr
I am working in ubuntu 8.10.
Angeline Aarthi
+2  A: 

On a Linux system, you'll probably have a sendmail script installed already, and PHP will use that. If this is what you have and it's not working, then I'd look for mail configuration problems in your Linux system itself.

On a Windows system, you'll need to configure the SMTP server you want PHP to send mail to. The normal way to do this is in php.ini. The instructions for this are here.

Unless you have set Email->delivery this should be the same for CakePHP - it should default to whatever PHP uses.

Note: If you are using your own Linux install, it could just be that your ISP is blocking port 25, which your mail server is using. In that case you'll need to configure linux to route email to your ISP's email server. Maybe this will help?

thomasrutter
I'm using ubuntu 8.10 and I have the send mail program also installed.Will it work only if I use the option for $this->Email->delivery as 'smtp'??
Angeline Aarthi
Email->delivery should default to 'mail', which would use PHP's mail() function which I described above. That would be most portable. As a troubleshooting measure though, I suppose it wouldn't hurt to try setting it to 'smtp' and setting Email->smtpOptions as shown in the documentation.
thomasrutter
thomasrutter
+1  A: 

Since when is 'to' (line 4) a valid destination email address?

Alister Bulman
Its just a variable name that is passed from the html file to the controller. It contains a valid email address typed in by the user.
Angeline Aarthi
That is a bad coding style, you should use $to and $subject.
christian studer
+1  A: 

You need to use variable syntax for setting to 'to' line, and the 'subject' line. Those lines should read

$this->Email->to      = to;
$this->Email->subject = subject;

Also, I believe there is an attribute in the Email component called error (I cannot find it in the documentation currently) that will help you debug. This may not be totally correct; I use the Email component with SMTP, and there is an attribute that gets set by the Email component called smtpError. I believe there is one called error that you can use to check for an error -- it should contain code that will tell you where your problem lies.

In case that's an incorrect statement, you can always do a var_dump( $this->Email ); after you try to send an email. That will dump the entire contents of the object, so you can see if you have set attributes correctly, and it should help you find out what the error attribute is named.

Travis Leleu