简体   繁体   中英

Codeigniter email issue with gmail

This is my code:

$this->email->from('your@example.com', 'Your Name');
$this->email->to('myemail@gmail.com');
$this->email->cc('myemail2@gmail.com');

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

$this->email->send();
echo $this->email->print_debugger();

This is the result of echo:

Your message has been successfully sent using the following protocol: mail

From: "Your Name" <your@example.com>
Return-Path: <your@example.com>
Cc: myemail2@gmail.com
Reply-To: "your@example.com" <your@example.com>
X-Sender: your@example.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <55058c9e98942@example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
=?utf-8?Q?Email_Test?=
Testing the email class.

I am testing a contact form. At first try I received the message, even if I got this message in gmail account "This message may not have been sent by: myemail@gmail.com"

I tried with the mail function from php:

$to = "myemail@gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: myemail2@gmail.com";

But I did not receive any email. What should I do ? What am I doing wrong ?

UPDATE:

        $config['protocol'] = 'sendmail';
        $config['charset'] = 'iso-8859-1';
        $config['wordwrap'] = TRUE;
        $config['priority'] = 1;

        $this->email->initialize($config);
        $this->email->from('your@example.com', 'Your Name');
        $this->email->to('cazare.carei.strand@gmail.com');
        $this->email->cc('naghi.attila@gmail.com');

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

        $this->email->send();
        echo $this->email->print_debugger(); exit();

If your port 25 is open, the e-mail should be sendable. Some e-mail providers require a valid mx record to be set in the DNS-Records of the e-mail's domain from the sender to prohid fake-emails of unauthorized senders being sent.

I am not sure if gmail has this requirement.

If you like to catch that issue you reconfigure the DNS entries of example.com to contain your server's ip address. An other possibility is to sendout the e-mail using a forign smtp server instead of your server's internal sendmail. I made the experience that this can be slow (on a big webabbplication).

As found on google , you can use with codignither for the protocol entry in the mail configuration also: 'sendmail'.

EDIT:

"This message may not have been sent by : myemail@gmail.com"

This might indicate that Google does not trust the sending server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM