我正在研究php codeigniter项目,我想从我的本地主机发送电子邮件。
以下是我的控制器功能。
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.google.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => 'password'
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from("[email protected]");
$this->email->to("[email protected]");
$this->email->subject("Email with Codeigniter");
$this->email->message("This is email has been sent with Codeigniter");
if($this->email->send())
{
echo "Your email was sent.!";
} else {
show_error($this->email->print_debugger());
}
请注意,我已经在php.ini中启用了'extension = php_openssl.dll'扩展名。我的php.ini文件位于C:/ AppServ / php5中。运行代码时,页面加载错误。
这些是错误:
遇到以下SMTP错误:1923818231无法找到套接字传输“ ssl”-在配置PHP时是否忘记启用它?无法发送数据:AUTH LOGIN无法发送AUTH LOGIN命令。错误:无法发送数据:MAIL FROM:
严重程度:警告
消息:date():依靠系统的时区设置是不安全的。您需要使用date.timezone设置或date_default_timezone_set()函数。如果您使用了这些方法中的任何一种,并且仍然收到此警告,则很可能您拼写了时区标识符。我们暂时选择了时区“ UTC”,但请设置date.timezone以选择您的时区。
文件名:libraries / Email.php
行号:705
使用PHPMailer。可在此处使用PHPMailer。您可以像这样使用它:
public function send_mail()
{
require_once(APPPATH.'third_party/PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // we are going to use SMTP
$mail->SMTPAuth = true; // enabled SMTP authentication
$mail->SMTPSecure = "ssl"; // prefix for secure protocol to connect to the server
$mail->Host = "smtp.gmail.com"; // setting GMail as our SMTP server
$mail->Port = 465; // SMTP port to connect to GMail
$mail->Username = "[email protected]"; // user email address
$mail->Password = "password"; // password in GMail
$mail->SetFrom('[email protected]', 'Mail'); //Who is sending
$mail->isHTML(true);
$mail->Subject = "Mail Subject";
$mail->Body = '
<html>
<head>
<title>Title</title>
</head>
<body>
<h3>Heading</h3>
<p>Message Body</p><br>
<p>With Regards</p>
<p>Your Name</p>
</body>
</html>
';
$destino = [email protected]; // Who is addressed the email to
$mail->AddAddress($destino, "Receiver");
if(!$mail->Send()) {
return false;
} else {
return true;
}
}
切记在您的gmail帐户中为不太受信任的应用设置访问权限
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句