Welcome Guest, Not a member yet? Register   Sign In
Sending mail from localhost using code igniter
#1

[eluser]gomathi jagannathan[/eluser]
Hi,

Iam trying to send mail from my localhost using code igniter. But iam getting following error

A PHP Error was encountered

Severity: Notice

Message: Undefined index: subject

Filename: controllers/email.php

Line Number: 74
A PHP Error was encountered

Severity: Notice

Message: Undefined index: message

Filename: controllers/email.php

Line Number: 76
A PHP Error was encountered

Severity: Warning

Message: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address

Filename: libraries/Email.php

Line Number: 1519



Can any one help to solve this issue
#2

[eluser]pistolPete[/eluser]
Post your controller code.
#3

[eluser]gomathi jagannathan[/eluser]
<?php
class Email extends Controller {

function Email(){

// load controller parent

parent::Controller();

// load 'url' helper

$this->load->helper('url');

// load 'form' helper

$this->load->helper('form');

// load 'validation' class

$this->load->library('validation');

// load 'email' class

$this->load->library('email');

}

function index(){

// set validation rules

$rules['firstname']="required|min_length[6]|max_length[15]";

$rules['lastname']="required|min_length[6]|max_length[15]";

$rules['email']="required|valid_email";

$this->validation->set_rules($rules);

// set values to repopulate fields

$fields['firstname']='First Name';

$fields['lastname']= 'Last Name';

$fields['email']='Email Address';

$this->validation->set_fields($fields);

// check if user form has been submitted properly

if ($this->validation->run()==FALSE){

// redisplay user form and repopulate fields

$this->load->view('form_view');

}

// display confirmation web page and send email

else{

// set email class settings

$this->email->from($_POST['email'],$_POST['firstname']. ' '.$_POST['lastname']);

$this->email->to('[email protected]');

$this->email->cc('[email protected]');

$this->email->bcc('[email protected]');

$this->email->subject($_POST['subject']);

$this->email->message($_POST['message']);

$data['title']='Sending email...';

$data['header']='Sending email now...';

$data['message']=$this->email->send()?'Message was sent successfully!':'Error sending email!';

$this->load->view('email_view.php',$data);

}

}

}
?>
#4

[eluser]pistolPete[/eluser]
Please use code tags.

How does the html form in your view look like?
The error messages you posted (Undefined index ...) tell you that there are no fields called "subject" and "message" in the POST data.

I have some general suggestions:

1) Use the Input Class to access POST data:
Code:
$email = $this->input->post('email');

2) Use the newer Form validation library, because the Validation library is deprecated as of CI 1.7.0 .

3)Have a look at the PHP Style Guide!
#5

[eluser]gomathi jagannathan[/eluser]
Hi frnd thanks for help..But still iam getting error like this...In my php.ini file i set the option like this

; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = [email protected]




A PHP Error was encountered

Severity: Warning

Message: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address

Filename: libraries/Email.php

Line Number: 1519
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

From: "Gomathi"
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Login_Information?=
Testing the email class.
#6

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter community!

$_POST['subject'] and $_POST['message'] do not exist in the $_POST array. You need to validate this information before sending the Email, and also, you should use $this->input->post() to access the post array.

EDIT: That only fixed half of your issue. Please come back when you've corrected this, and repost the errors you're getting.
#7

[eluser]Unknown[/eluser]
[quote author="gomathi jagannathan" date="1236181481"]Hi frnd thanks for help..But still iam getting error like this...In my php.ini file i set the option like this

; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = [email protected]




A PHP Error was encountered

Severity: Warning

Message: mail() [function.mail]: SMTP server response: 501 5.5.4 Invalid Address

Filename: libraries/Email.php

Line Number: 1519
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

From: "Gomathi"
Return-Path:
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Login_Information?=
Testing the email class.[/quote]

I have the same problem with this too. Any suggestion?




Theme © iAndrew 2016 - Forum software by © MyBB