我使用codeigniter
我在实时服务器上删除了代码。 使用print_debugger()
得到以下错误无法使用PHP SMTP发送电子邮件。您的服务器可能不是 配置为使用此方法发送邮件。
public function sendEnquiry() {
$this->load->library('email');
$name = $this->input->post("fname");
$cemail = $this->input->post("email");
$pno = $this->input->post("phone");
$message = $this->input->post("message");
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://mail.gatewaykhobar.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = '***********';
$config['smtp_pass'] = '***********';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'text'; // or html
$config['validation'] = FALSE;
$this->email->initialize($config);
$this->email->from('info@gatewaykhobar.com','Gateway Restaurent Contact');
$this->email->to($cemail);
$this->email->subject('Gateway Restaurent Contact Enquiry');
$this->email->message($message);
$send = $this->email->send();
if($send) {
echo json_encode("send");
} else {
$error = $this->email->print_debugger(array('headers'));
echo json_encode($error);
}
}
答案 0 :(得分:9)
将smtp_port从465更改为587 确保$ config ['换行符'] =" \ r \ n&#34 ;;是双引号而不是单引号
答案 1 :(得分:2)
一个常见的原因是CodeIgniter与SMTP服务器之间有关换行的交互方式。您的SMTP服务器可能需要\r\n
,而CodeIgniter正在使用\n
。
有一个简单的解决方法:在您的$this->email->initialize()
之后,添加以下内容:
$this->email->set_newline("\r\n");
那应该可以为您工作。
答案 2 :(得分:2)
q)a:("12";"34";"56")
q)bb:([]c:("90";"12";"65"))
q)([]c:a) except bb
c
----
"34"
"56"
我刚刚添加了最后一行
答案 3 :(得分:1)
我花了很多时间在 localhost 中运行我的配置代码,但它总是给我一个错误(无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。 )
但是在我的服务器中运行下面的代码时,它对我有用。
应用程序>控制器> Sendingemail_Controller.php
public function send_mail() {
$this->load->library('email');
$config = array();
$config['protocol'] = "smtp"; // you can use 'mail' instead of 'sendmail or smtp'
$config['smtp_host'] = "ssl://smtp.googlemail.com";// you can use 'smtp.googlemail.com' or 'smtp.gmail.com' instead of 'ssl://smtp.googlemail.com'
$config['smtp_user'] = "my@gmail.com"; // client email gmail id
$config['smtp_pass'] = "******"; // client password
$config['smtp_port'] = 465;
$config['smtp_crypto'] = 'ssl';
$config['smtp_timeout'] = "";
$config['mailtype'] = "html";
$config['charset'] = "iso-8859-1";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$config['validate'] = FALSE;
$this->load->library('email', $config); // intializing email library, whitch is defiend in system
$this->email->set_newline("\r\n"); // comuplsory line attechment because codeIgniter interacts with the SMTP server with regards to line break
$from_email = $this->input->post('f_email'); // sender email, coming from my view page
$to_email = $this->input->post('email'); // reciever email, coming from my view page
//Load email library
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->subject('Send Email Codeigniter');
$this->email->message('The email send using codeigniter library'); // we can use html tag also beacause use $config['mailtype'] = 'HTML'
//Send mail
if($this->email->send()){
$this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
echo "email_sent";
}
else{
echo "email_not_sent";
echo $this->email->print_debugger(); // If any error come, its run
}
}
,以及我在其中定义 f_email 和 email 的视图页面通过发布方法。 application> view> emailtesting.php
<html>
<head>
<title> Send Email Codeigniter </title>
</head>
<body>
<?php
echo $this->session->flashdata('email_sent');
echo form_open('/Sendingemail_Controller/send_mail');
?>
<input type = "email" name = "f_email" placeholder="sender email id (from)" required />
<input type = "email" name = "email" placeholder="reciever email id (to)" required />
<input type = "submit" value = "SEND MAIL">
<?php
echo form_close();
?>
</body>
如果再次出现错误,请访问下面的官方文档:
答案 4 :(得分:0)
看起来邮件服务器也是由您自己托管,尝试从任何电子邮件客户端发送电子邮件。如果失败 - 您的邮件服务器配置存在问题,而不是您粘贴的代码 - 请检查服务器日志。
答案 5 :(得分:0)
只需对“协议”数组项使用“邮件”,就可以了。
$config = array();
$config['useragent'] = $system_name;
$config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
$config['protocol'] = "mail"; //use 'mail' instead of 'sendmail or smtp'
$config['smtp_host'] = "your domain name";
$config['smtp_user'] = $from;
$config['smtp_pass'] = "*************";
$config['smtp_port'] = 465;
$config['smtp_crypto'] = 'ssl';
$config['smtp_timeout'] = "";
$config['mailtype'] = "html";
$config['charset'] = "utf-8";
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$config['validate'] = FALSE;