如何在 localhost(wampserver) 中使用 php codeigniter 发送邮件 (sendmail)。
第一阶段:从这个网站下载sendmail glob.com .
第二阶段:解压 sendmail zip 文件并将其放入 wampserver 目录。
第三阶段:打开 sendmail 文件夹并在记事本中选择 sendmail.ini 文件并在其中更改一些行:
1.smtp_server=smtp.gmail.com
2.smtp_port=465
3.smtp_ssl=ssl
4.default_domain=localhost
5.error_logfile=error.log
6.debug_logfile=debug.log
7.auth_username=你的邮件(example@gmail.com)
8.auth_password=您的邮件真实密码
9.force_sender=你的邮件(example@gmail.com)
10.hostname=localhost
第四阶段:打开该地址(E:\wamp64\bin\apache\apache2.4.37\bin)下的php.ini文件
第五阶段:在此处更改一些行并将 sendmail.exe 地址放入 sendmail_path 中,如下所示:
ctrl+f -> 你必须搜索(邮件功能)并在 sendmail.ini 中找到它
[mail function];
For Win32 only.
SMTP =
smtp_port =
; For Win32 only.
sendmail_from =
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path ="E:\wamp64\sendmail\sendmail.exe -t -i"
第六阶段:根据你安装wampserver的位置和你使用的php版本打开(E:\wamp64\bin\php\php7.2.14)地址中的php.ini
第七阶段:在此处更改一些行:
ctrl+f -> 你必须像下面这样搜索(邮件功能)。
[mail function]
; For Win32 only.
SMTP =
smtp_port = 25
; For Win32 only.
sendmail_from ="admin@wampserver.invalid"
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path ="E:\wamp64\sendmail\sendmail.exe -t -i"
第八阶段:用桌面右下角的图标重新启动 wampserver。
第九阶段:通过右键单击 wampserver 图标选择 apache/apache_module/ssl_module
启用 ssl_module
第十阶段:通过右键单击 wampserver 图标选择 php/php_extensions/open_ssl 和 php/php_extensions/sockets
启用 open_ssl 和套接字
再次重启 wampserver
第 11 阶段:从控制器内部的 codeignter 中的视图中获取数据,并将这些代码保存在控制器中:
if (isset($_POST['btn_send_contact_form'])) {
$data = $_POST['frm'];
$firstname = $data['firstname'];
$lastname = $data['lastname'];
$email = $data['email'];
$msg_title = $data['msg_title'];
$msg_text = $data['msg_text'];
$this->load->library('email'); // email library must be included.
$this->email->from($email, $firstname);
$this->email->to('yourmail@gmail.com'); // the receiver mail
// $this->email->cc('another@another-example.com');
// $this->email->bcc('them@their-example.com');
$this->email->subject($msg_title);
$this->email->message($msg_text);
$res = $this->email->send();
if ($res) {
header("location: contact_us?contactUs_mail_sending=successful");
} else {
header("location: contact_us?contactUs_mail_sending=error");
}
}
$this->load->view('pages/contact_us');
第 12 阶段:(重要)在您的 gmail 帐户的设置/安全中启用(不太安全的应用访问)。
第十三阶段:发送邮件成功。
注意:如果一切正常,请尝试(在您的 gmail 帐户中启用不太安全的应用程序访问,虽然不建议这样做,但它可以让您发送一封简单的电子邮件(在 gmail 帐户中)。
希望有用。