我正在发送我的代码,但发送电子邮件时出现以下错误。
遇到PHP错误严重性:警告消息:mail() [function.mail]:无法连接到" localhost"的邮件服务器港口 25,验证你的" SMTP"和" smtp_port"在php.ini中设置或使用 ini_set()文件名:libraries / Email.php行号:1554
代码如下。
email.php文件如下。
<?php
class Email extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('form');
}
public function index()
{
$this->load->view('contact');
}
public function send()
{
$this->load->library('email');
$name=$this->input->post('name');
$form=$this->input->post('form');
$subject=$this->input->post('sub');
$msg=$this->input->post('message');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl:/gamil.smtp.com';
$config['smtp_port'] = 25;
$config['smtp_user'] ='rameshjadav133@gmail.com';
$config['smtp_pass'] ='jadav4545';
$this->load->library('email',$config);
$this->email->from($form,$name);
$this->email->to('rameshjadav133@gmail.com');
$this->email->subject($subject);
$this->email->message($msg);
if($this->email->send())
{
$data = array('message' =>'Email send success fulll....' );
}
else
{
$data = array('message' => 'Email not send' );
}
$this->load->view('contact',$data);
}
}
?>
contact.php文件如下。
<!DOCTYPE html>
<html>
<head>
<title>Contact form</title>
</head>
<body>
<?php
if(isset($message))
{
echo $message;
}
echo "<h1>Contact form </h1>";
echo form_open("email/send");
echo form_label("Name : ");
echo form_input("name");
echo "<br>";
echo form_label("From : ");
echo form_input("from");
echo "<br>";
echo form_label("Subject : ");
echo form_input("sub");
echo "<br>";
echo form_label("Message");
$data = array('name' => 'message','rows'=>5,'cols'=>32 );
echo form_textarea($data);
echo "<br>";
echo form_submit('submit','send Email');
echo form_close();
?>
</body>
</html>