doujiao1814 2016-04-04 09:34
浏览 92

在codeigniter中以不同形式发送电子邮件

I need some help pls. I'm building this website using C.I 3 and it has like 3 different forms with 3 different pages (career, quote, contact) where users can fill them up and i will receive an email but only contact page is working and the remain two pages prompt and error (Unable to send email using PHP mail(). Your server might not be configured to send mail using this method) while they all fall under the same controller. can anyone help me solve this issue pls? below is the link to my codes

http://pastebin.com/REFjPsUf

Thanks

defined('BASEPATH') OR exit('No direct script access allowed');

class Site extends CI_Controller {
public function index(){
    $this->home();
}
public function home(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("home_content");
    $this->load->view("footer");

}
public function aboutUs(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("content_about");
    $this->load->view("footer");
}
public function projects(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("content_project");
    $this->load->view("footer");

}
public function services(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("content_service");
    $this->load->view("footer");

}
public function careers(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("content_career");
    $this->load->view("footer");

}
public function gallery(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("content_gallery");
    $this->load->view("footer");

}
public function register(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("slider");
    $this->load->view("quote");
    $this->load->view("footer");

}


public function contact(){
    $this->load->view("home_header");
    $this->load->view("site_nav");
    $this->load->view("contact_header");
    $this->load->view("content_contact");
    $this->load->view("footer");

}


public function sendmail(){




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



    $this->email->from($this->input->post("email"), $this->input->post("name"));
    $this->email->to("me@example.com");


    $this->email->subject('from website contact form');

    $this->email->message($this->input->post("message"));


    if ( ! $this->email->send())
    {
            echo $this->email->print_debugger(); // Generate error
    }
    else{
        $this->load->view("home_header");
        $this->load->view("site_nav");
        $this->load->view("contact_header");
        $this->load->view("contact_success");
        $this->load->view("footer");
    }


}


public function quotation(){




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



    $this->email->from($this->input->post("email"));
    $this->email->to("me@example.com");


    $this->email->subject($this->input->post("subject"));

    $this->email->message($this->input->post("message"));


    if ( ! $this->email->send())
    {
            echo $this->email->print_debugger(); // Generate error
    }
    else{
        $this->load->view("home_header");
        $this->load->view("site_nav");
        $this->load->view("slider");
        $this->load->view("quote_success");
        $this->load->view("footer");
    }
} 


public function mycareer(){


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



    $this->email->from($this->input->post("email"));
    $this->email->to("me@example.com");

    $this->email->subject($this->input->post("subject"));

    $this->email->message($this->input->post("message"));

    if (!$this->email->send()){
        echo $this->email->print_debugger();
    }
    else{
        echo "Email sent";
    }


}

}

  • 写回答

3条回答 默认 最新

  • dsgdhf5674 2016-04-04 14:21
    关注

    **try on smtp config in ci as

    $this->email->initialize(array(
      'protocol' => 'smtp',
      'smtp_host' => 'xxxx.ipage.com',//SMTP servern name
      'smtp_user' => 'user@xxxx.com',
      'smtp_pass' => 'SMTP user password',
      'smtp_port' => 587,//port
      'crlf' => "
    ",
      'mailtype' => 'html',
      'newline' => "
    ",
    'wordwrap' => TRUE
    ));
    
    $this->email->from($email,$name);
    $this->email->to('admin@xxxx.com'); 
    $this->email->cc('user@xxxx.com'); 
    $this->email->bcc('xxxxx@gmail.com'); 
    
    $this->email->subject('Email Test');
    $this->email->message($message1);   
    
    if($this->email->send())
    echo "<script>alert('Thank you... mail Sent');</script>";
    else
    echo "<script>alert('Not Sent Please Try again');</script>";
    redirect('xxxx/abc');
    

    OR you can use PHP-mail class also.. just download from GitHub or in php official site. then paste it in view folder then include it.. that's it.

    <?php
    
    //SMTP needs accurate times, and the PHP time zone MUST be set
    //This should be done in your php.ini, but this is how to do it if you don't have access to that
    //date_default_timezone_set('Etc/UTC');
    
    require __DIR__.'/phpmailer/PHPMailerAutoload.php';
    
    //Create a new PHPMailer instance
    $mail = new PHPMailer();
    //Tell PHPMailer to use SMTP
    $mail->isSMTP();
    //Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug   = 2;
    //$mail->DKIM_domain = '160.153.33.231';
    //Ask for HTML-friendly debug output
    $mail->Debugoutput = 'html';
    //Set the hostname of the mail server
    $mail->Host        = "mail.xxxx.com";
    //Set the SMTP port number - likely to be 25, 465 or 587
    $mail->Port        = 465;
    //Whether to use SMTP authentication
    $mail->SMTPAuth    = true;
    //Username to use for SMTP authentication
    $mail->Username    = "info@xxxxx.com";
    //Password to use for SMTP authentication
    $mail->Password    = "xxxxx";
    $mail->SMTPSecure  = 'ssl';
    
    if(isset($from,$sender)){
        //Set who the message is to be sent from
        $mail->setFrom($from, $sender);
    }
    else $mail->setFrom("info_@xxxxx.com", 'from Website');
    
    
    
    //Set an alternative reply-to address
    //$mail->addReplyTo('info_@xxxx.com', 'First Last');
    //Set who the message is to be sent to
    $mail->addAddress('care@xxxxxx.com', 'xxxxxx.com');
    
    //$mail->AddBCC('xxxx@gmail.com','');
    //Set the subject line
    $mail->Subject = $subject;
    
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML($body_tmp);
    //Replace the plain text body with one created manually
    
    $mail->AltBody = 'This is a plain-text message body';
    //Attach an image file
    //$mail->addAttachment('images/phpmailer_mini.png');
    
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
    //echo $body_tmp;
    ?>**
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度