簡體   English   中英

在codeigniter中以不同的形式發送電子郵件

[英]sending emails form different forms in codeigniter

我需要一些幫助。 我正在使用CI 3構建此網站,它具有3種不同的表單,其中包含3種不同的頁面(職業,報價,聯系方式),用戶可以在其中填寫內容,我會收到一封電子郵件,但只有聯系頁面有效,其余兩頁提示和錯誤(無法使用PHP mail()發送電子郵件。您的服務器可能未配置為使用此方法發送郵件),但它們都屬於同一控制器。 有人可以幫我解決這個問題嗎? 以下是我的代碼的鏈接

http://pastebin.com/REFjPsUf

謝謝

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";
    }


}

}

最后兩個函數“ quotation() and mycareer() ”中的代碼中有錯誤,缺少$this->email->from()的第二個參數

參考鏈接

$this->email->from($this->input->post("email") , 'Your Name');

希望對你有效。

**嘗試在ci中的smtp配置為

$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' => "\r\n",
  'mailtype' => 'html',
  'newline' => "\r\n",
'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');

或者,您也可以使用PHP-mail類。只需從GitHub或php官方站點下載即可。 然后將其粘貼到視圖文件夾中,然后包括它..就是這樣。

<?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;
?>**

很多人在使用“聯系我們”表格時也會遇到一個非常常見的錯誤。

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

如果您使用的郵件服務器已啟用DMARC,則這將破壞SPF並導致DMARC失敗,並且您將永遠不會收到來自某些人的消息。

由於DMARC是較新的協議,因此許多用於與我們聯系的舊的Cookie切割器代碼都沒有考慮在內。

您可以在此處了解更多信息: “ DMARC-噩夢聯系表”

建議的解決方法是:

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

這樣-您可以避免文章中的問題概述。 您將無法快速單擊“答復”按鈕,但是至少您會收到那些啟用了DMARC的客戶的電子郵件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM