0

I have a simple mail function in my page. I use Test Mail Server Tool to check it on local system and it is sending the mail. But when I upload the files to server it is not sending the file

Here is the email code :

if($_POST['name'])
{
    $subject = "Message from website";
    $name = $_POST['name'];
    $email = $_POST['email'];
    $number = $_POST['number'];
    $txt = " Name : " . $name . " \r\n Email : " . $email . " \r\n Contact No. : " . $number;
    $headers = 'From:' . $name . "\r\n";
    $mail=mail('xyz@gmail.com', $subject, $txt, $headers);

    if($mail)
    {

        echo "Thank You!";
    }

    if(!$mail)
    {
        echo "failed";
    }
}
else
    echo "no values entered";

I see 'thank you' message on localhost.But when I upload to server its showing the message 'failed'.

Please help.

Thanks in advance.

Abdulla
  • 441
  • 1
  • 9
  • 21

2 Answers2

-1

Add the below lines in your coding.

`$this->load->library('email'); 
$config['protocol'] = 'mail'; 
$config['charset'] = 'utf-8'; 
$this->email->initialize($config); 
$this->email->set_mailtype('html');'
Nisha .A
  • 46
  • 7
-1

Mail functionality

$msg = "<html>

                                    <body>
                                    User Contact Details
                                    <table>
                                    <tr><td>Name:</td><td>".$_POST['name']."</td></tr>

                                    <tr><td>Mobile:</td><td>".$_POST['mobile']."</td></tr>
                                    <tr><td>Email :</td><td>".$_POST['email']."</td></tr>
                                    </table>
                                    </body>

                                    </html>

                                    ";

$this->load->library('email'); 
$config['protocol'] = 'mail'; 
$config['charset'] = 'utf-8'; 
$this->email->initialize($config); 
$this->email->from('From email id'); 
$this->email->to('$_POST['email']'); 
$this->email->subject('Subject of ur email id'); 

$this->email->message($msg); 
$this->email->set_mailtype('html');
 if($this->email->send())
     {

      echo 'Thank you';

     }
     else
    {
         echo "failed";
    }
Nisha .A
  • 46
  • 7