4

Today I made a contact form on my website. All is working fine, the emails are sending correctly to the specified email ($this->email->to('myemail@address.com')).

In my application/config/email.com I have:

$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'
);

But now every mail I send from my website are recieved as 'myemail@gmail.com' when I look into the mailbox of myemail@address.com.

I don't know if this is the standard behaviour?

How can I use the email typed in into the input box as the 'from' email?

My controller function looks like this:

    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());
        }
    }

Hope someone can help.

Kees Sonnema
  • 5,759
  • 6
  • 51
  • 106

1 Answers1

2

My guess is that Gmail restricts any arbitrary "from" address. Why ? To prevent spoofing.

(Imagine if it were possible, you could send anyone an email from "big_bank@blabla.com"...)

EDIT : A quick google search yielded this : 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.

Source : https://stackoverflow.com/a/1332803/2615399

Tl;dr : you can't (...using gmail).

Community
  • 1
  • 1
Organ
  • 453
  • 2
  • 6