简体   繁体   中英

sending email using gmail SMTP, does the 'from' field matters? do I need to set account permission first?

I'm using codeigniter 2.1.4 to send email using gmail's smtp. Here is my config:

$config['protocol'] = 'smtp';
$config['smtp_crypto'] = 'ssl';
$config['smtp_host'] = 'smtp.gmail.com';
$config['smtp_user'] = 'myaccount@gmail.com';
$config['smtp_pass'] = 'my secret password';
$config['smtp_port'] = '465';
$config['newline'] = "\r\n";

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

$this->email->from('xxxxxxx', '');
$this->email->to('johndoe@gmail.com');

$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');

I wonder $this->email->from('xxxxxxx', ''); if I should always put myaccount@gmail.com (same as the username that I use for the smtp user field. I wonder if I can change it to something like something@server-hostname.

Also I want to know if I need to set the account permission ( https://support.google.com/accounts/answer/3466521 ) before using this gmail smtp. I found out that there are times that I can't send email using the exact same configuration. I have to resend it few times (each time it will generate the gmail authentication failed error). then I have to login to my myaccount@gmail.com (smtp username) account's recent activity page ( https://support.google.com/mail/answer/45938?hl=en ) and remove the unusual activity. Once I have removed the unusual activity then I can send email without any error.

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