-1

我是 Codeigniter 的菜鸟,我想制作一个联系表格,我希望将其发送到我的 gmail。我提出了一个观点:

<div id="content">
<?php if (isset($mail_sent)): ?>
<b>Mail Sent</b>
<?php endif; ?>

<form action="<?php echo base_url() ?>" method="POST">

<b>Your Name :</b>
<br />
<input type="text" name="name" />
<br />
<b>Your Email Address:</b>
<br />
<input type="text" name="from" />
<br />
<b>Subject :</b>
<br />
<input type="text" name="subject" />
<br />
<b>Message :</b>
<br />
<textarea name="message" rows="10" cols="15"></textarea>
<br />
<input type="submit" name="q" value="Contact" />

</form>
</div>

我在我的联系页面中的同一控制器代码块中有邮件设置。它看起来像这样:

public function contact()
{
    $this->load->view('header');
    $this->load->view('owrb_contact');
    $this->load->view('footer');

    $config['protocol'] = 'sendmail';
    $config['mailpath'] = '/usr/sbin/sendmail';
    $config['charset'] = 'iso-8859-1';

    // gmail specific settings here
    $config['smtp_host'] = 'smtp.gmail.com';
    $config['smtp_user'] = 'keessonnema@gmail.com';
    $config['smtp_pass'] = '123keesje123';
    $config['smtp_port'] = '465';

    $config['wordwrap'] = TRUE;

    $this->load->library('email');
    $this->email->initialize($config);

    $this->email->from('keessonnema@gmail.com', 'Kees Sonnema');

    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');  

    $this->email->send();
}

现在我必须配置一个 smtp gmail 控制器?我真的不知道该怎么做。

谢谢

4

1 回答 1

2

你可以使用 Codeigniter 框架发送邮件,这里有描述。

http://ellislab.com/codeigniter/user-guide/libraries/email.html

有协议、服务器和您可能希望配置的每个项目的设置。如果您愿意,也可以将其与 gmail 连接。

$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';

// gmail specific settings here
$config['smtp_host'] = '';
$config['smtp_user'] = '';
$config['smtp_pass'] = '';
$config['smtp_port'] = '';

$config['wordwrap'] = TRUE;

$this->load->library('email');
$this->email->initialize($config);

$this->email->from('your@example.com', 'Your Name');

$this->email->subject('Email Test');
$this->email->message('Testing the email class.');  

$this->email->send();
于 2013-02-21T10:27:51.440 回答