php – Codeigniter电子邮件始终从’my@gmail.com’发送而不是给出的输入电子邮件

今天我在我的网站上发了一个联系表格.一切正常,电子邮件正确发送到指定的电子邮件($this-> email-> to(‘mymail@address.com’)).

在我的application / config / email.com中,我有:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'myemail@gmail.com',
    'smtp_pass' => 'mypassword',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);

但是,当我查看myemail@address.com的邮箱时,我从我的网站发送的每封邮件都被收到“myemail@gmail.com”.

我不知道这是否是标准行为?

如何将输入框中输入的电子邮件用作“来自”电子邮件?

我的控制器功能如下所示:

    public function sendmail()
    {
        $config['mailtype'] = 'html';
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_port'] = 465;
        $config['smtp_user'] = 'user@gmail.com';
        $config['smtp_pass'] = 'user@owrb';
        $confog['wordwrap'] = TRUE;

        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");

        $this->email->from($this->input->post('from'), $this->input->post('name'));

        $this->email->to('info@keessonnema.nl');    

        $this->email->subject($this->input->post('subject'));      

        $naam = $this->input->post('name');
        $email = $this->input->post('from');
        $tel = $this->input->post('tel');
        $site = $this->input->post('site');
        $sub = $this->input->post('subject');
        $msg = $this->input->post('message');

        $this->email->message("
        <div id='email'>
        <p><b>Bedrijf:</b> <br/> $naam</p>
        <p><b>Email:</b> <br/> $email</p>
        <p><b>Tel:</b> <br/> $tel</p>
        <p><b>Website:</b> <br/> $site</p>
        <p><b>Onderwerp:</b> <br/> $sub</p>
        <p><b>Toelichting:</b> <br/> $msg</p>
        </div>
        ");

        $success = ('
        <div style="position: absolute; top: 50%; left: 50%; background-color: rgba(0,0,0,0.8);">Uw Email is succesvol verzonden!</div>
        ');

        if($this->email->send())
        {
            $this->session->set_flashdata('msg', 'Email successvol verzonden.');
            redirect('contact/index');
        }
        else
        {
            show_error($this->email->print_debugger());
        }
    }

希望有人能提供帮助.

最佳答案 我的猜测是,Gmail会限制任意“来自”地址.

为什么?防止欺骗.

(想象一下,如果有可能,你可以发送任何人发送电子邮件至“big_bank@blabla.com”……)

编辑:快速谷歌搜索产生了这个:How to change from-address when using gmail smtp server

Google rewrites the From and Reply-To headers in messages you send via
it’s SMTP service to values which relate to your gmail account.

The SMTP feature of gmail isn’t intended to be an open or relay
service. If it allowed any values for the From header, it would
significantly dilute Google’s standing with spam services, as there
would be no way to verify the credentials of the sender.

资料来源:https://stackoverflow.com/a/1332803/2615399

Tl;博士:你不能(……使用gmail).

点赞