2017-03-30 07:39
浏览 49

在codeigniter php中发送电子邮件后无法显示成功消息

Hi i am having a request form same as contact form once i send the mail not able to display any success message once i send email.Not displaying any success message or failure message after sending email.


function request()
        $this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
        $this->form_validation->set_rules('name','First Name' , 'required');
        $this->form_validation->set_rules('phone','Mobile Number','required|numeric');
        if($this->form_validation->run()== FALSE)   

        echo "hi";
        //get the form data
        $name = $this->input->post('name');
        $from_email = $this->input->post('email');
        $phone = $this->input->post('phone');
        $description = $this->input->post('description');       

        //set to_email id to which you want to receive mails
        $to_email = '';

    'protocol'=> 'smtp',
    'smtp_host' => 'ssl://', //smtp host name
    'smtp_port' => '465', //smtp port number
    'smtp_user' => '',
    'smtp_pass' => 'abcdefgh', //$from_email password
    'mailtype' =>'html',
    'newline'  =>"
    'crlf' =>"
    'charset' => 'iso-8859-1',
    'wordwrap' => TRUE

    $message            = array();    
$message[] = 'Username  :  '.trim($name).' ';
$message[] = 'Phone Number :  '.trim($phone).' ';
$message[] = 'Description :  '.trim($description).' ';
$message = implode(PHP_EOL, $message);
    //send mail
    $this->email->subject('Request Free Quote');

        if ($this->email->send())
            // mail sent
            echo "hi";
            $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your mail has been sent successfully!</div>');
            $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">There is error in sending mail! Please try again later</div>');


<div class="col-md-3 requestfree">
<img src="<?php echo base_url();?>theme/images/icon1.png" class="requesting">
<h3 class="request">REQUEST</h3>
<h5 class="free"> FREE QUOTE</h5>
<h5 class="receive">You will receive quote within 24 hours</h5>
<form name="contact"  id="contactform" enctype="multipart/form-data" method="post" action="<?php echo base_url();?>welcome/request">
<?php if(isset($msg)){?>
     <?php echo $msg;?>
       <?php } ?>

<div class="name"><span class="mandatory"></span>
    <input type="text" class="form-control" name="name" placeholder="Name" required>
    <?php echo form_error('name', '<div class="error">', '</div>'); ?>
<div class="name">
    <input type="text" class="form-control" name="phone" placeholder="Phone" required>
    <?php echo form_error('phone', '<div class="error">', '</div>'); ?>
<div class="email">
    <input type="email" class="form-control" name="email" placeholder="Email" required>
    <?php echo form_error('email', '<div class="error">', '</div>'); ?>
<div class="description">
    <textarea name="description"  style="width:100%;overflow:auto;" placeholder="Description" required></textarea>
<div class="">
    <div class="captchas">
        <img src="captcha.php?rand=<?php echo rand();?>" class="captchass" id='captchaimg'/>
        <p class="change"><a href="javascript: refreshCaptcha();" class="clickto">click to change</a></p>
    <div class="captcha">
        <input type="text" class="form-control"id="captcha_code" name="captcha_code"  style="background-color: #EAD5D2;border: none;">
<input type="hidden" value="true" name="isSubmitted">
<button type="submit" class="btn btn-success" onclick="return validate();"  >Submit</button><!--  id="demo"!-->
<div class='message'>  
<p class="thankyou">
Thank You
Our team will contact you shortly.
<p class="privacy">We respect your privacy</p>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumang20060820 2017-03-30 08:05

    try in your view

    echo $this->session->flashdata('msg');
    解决 无用
    打赏 举报

相关推荐 更多相似问题