Home Redirection not working after sending Email in CakePHP
Reply: 0

Redirection not working after sending Email in CakePHP

user6708
1#
user6708 Published in September 20, 2018, 9:15 pm

I am sending a Email in Contact-Us form in CakePHP 2. Mail is being send properly but the problem is after sending Email it is not redirecting to Home page. I am using SMTP to send email.

My Controller method

public function contactForm()
{
    if ($this->request->is(['post','put'])) {
        $name = $this->request->data['home']['name'];       
        $email = $this->request->data['home']['email'];
        $phone = $this->request->data['home']['phone'];
        $message = $this->request->data['home']['message'];

        $emailMessage = "Name - $name\n";
        $emailMessage .= "Email - $email\n";
        $emailMessage .= "Phone - $phone\n";
        $emailMessage .= "Message - $message\n";


        $Email = new CakeEmail();
        $Email->config('smtp');
        $Email->from(array($email =>$name));
        $Email->to('info@myserver.com');
        $Email->subject('Contact Us - Form');
        $Email->send($emailMessage);
        $this->Session->setFlash('Thank for contacting us. Our representative will reach you soon.','flash', array('alert'=> 'success'));
        $this->redirect(array('action' => 'index'));
    }           
}

The index method is also there. Here is my HTML form

<?php echo $this->Form->create('home', array( 'controller' => 'homes', 'action' => 'contactForm','name'=>'contact-form','id'=>'contact-form','class'=>'contact-form'));?>
            <div class="row flex-box">
                <fieldset class="column column-1-2">
                    <label>YOUR NAME</label>
                    <?php echo $this->Form->input('name',array('type'=>'text','id'=>'name','value'=>'','label' => false,'class'=>'text-input validate[required]','div'=>false));?>
                    <label>YOUR EMAIL</label>
                    <?php echo $this->Form->input('email',array('type'=>'email','id'=>'email','value'=>'','label' => false,'class'=>'text-input validate[required]','div'=>false));?>
                    <label>YOUR PHONE</label>
                    <?php echo $this->Form->input('phone',array('type'=>'tel','id'=>'phone','value'=>'','label' => false,'class'=>'text-input validate[required]','div'=>false));?>
                </fieldset>
                <fieldset class="column column-1-2">
                    <label>MESSAGE</label>
                    <?php echo $this->Form->input('message',array('type'=>'textarea','id'=>'content','value'=>'','div'=>false));?>
                </fieldset>
            </div>
            <div class="row margin-top-30">
                <div class="column column-1-1">
                    <div class="row margin-top-15 padding-bottom-16 align-center">
                        <button type="submit" class="more submit-contact-form" style="display:inline-block;">Send message</button>
                    </div>
                </div>
            </div>
        </form>

I am receiving mail properly. Not able to distinguish what is the error. Any help will be appreciated.

share|improve this question

1 Answer 1

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.282379 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO