我正在尝试在codeIgniter中发送电子邮件,我收到了example@mycompany.com
上的电子邮件但是无法在gmail中收到它们
我试过这个:
$this->load->library('email');
$config['useragent'] = 'CodeIgniter';
$config['smtp_host'] = 'smtp.googlemail.com';
$config['protocol'] = 'smtp';
$config['smtp_user'] = 'example@gmail.com';
$config['smtp_pass'] = '**********';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 30;
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->from('no-reply@mycompany.com', 'My company');
$this->email->to($email);
$this->email->subject('hello');
$this->email->message($message);
$this->email->set_mailtype('html');
$this->email->send();
答案 0 :(得分:1)
尝试以下配置。此外,您还必须从Gmail帐户中安全性较低的应用
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'example@gmail.com',
'smtp_pass' => '**********',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'mailtype' => 'html',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
答案 1 :(得分:-1)
Download the php mailer library in the following link:https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.26.
After download complete create phpmailer folder in library and extract the zip in php mailer folder...
<?php
require 'phpmailer/src/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "xxxxxxx@gmail.com";
$mail->Password = "xxxxxxxxx";
$mail->setFrom('from@example.com', 'First Last');
$mail->addAddress('whoto@example.com', 'John Doe');
$mail->Subject = 'Add subject';
$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}