chandan
chandan

Reputation: 2453

How to send mail in PHP by using ubuntu operating system?

This is my code and I include all files such mime.php, mail.php and Mail.php in my project folder but still mail functioning is not working.

<?php
require "Mail.php";
require_once 'Mail/mime.php';
require_once 'Mail/mail.php';

$to = "[email protected]";
$from = "[email protected]";
$subject = utf8_decode("mail");
$message = utf8_decode("hi");
$attachment_data = utf8_decode("testingmail1-filecontent");
$attachment_filename = utf8_decode("testingmail1.php");
send_mail_utf8_with_attachment($to, $from, $subject, $message ,$attachment_data, $attachment_filename);

function send_mail_utf8_with_attachment($to, $from, $subject, $message = "",$attachment_data="", $attachment_filename="")
{
    $params = array();
    $params['head_charset'] = 'utf-8';
    $params['text_charset'] = 'utf-8';
    $params['html_charset'] = 'utf-8';
    $params['eol'] = "\n";
    $hdrs = array('From'    => $from ,'Subject' => $subject );
    $mime = new Mail_mime($params);
    $mime->setTXTBody($message);

    if (strlen($attachment_data) && strlen($attachment_filename))
    {
        $mimeType = "application/octet-stream";
        $mime->addAttachment($attachment_data, $mimeType, $attachment_filename, false);
    }

    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    $mail =& Mail::factory('mail');
    return $mail->send($to, $hdrs, $body);
} 
?>

I have implemented all instalation :

sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime

But still it is not working.

Upvotes: 1

Views: 3926

Answers (2)

haltabush
haltabush

Reputation: 4528

You must have a SMTP server configured on your Ubuntu. I personally usually use ssmtp & gmail Have a look there for the related tuto : http://blog.seeit.org/2010/08/php-mail-with-ubuntu-desktop-and-gmail/

Upvotes: 2

tonymarschall
tonymarschall

Reputation: 3882

Maybe your php.ini settings for sending mails are not correct. Try something like mail('[email protected]', 'My Subject', $message);. If this is working your mail settings in php.ini are correct.

Upvotes: 1

Related Questions