我正在使用codeigniter并使用电子邮件库发送电子邮件。
参考:https://www.codeigniter.com/user_guide/libraries/email.html
$CI->email->initialize(array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_user' => 'mymailid@gmail.com',
'smtp_pass' => 'mypassword',
'smtp_port' => 465,
'crlf' => "\r\n",
'newline' => "\r\n",
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
));
$CI->email->from('companyadmin@company.com', 'Company Admin');
$CI->email->reply_to('companyadmin@company.com', 'Company Admin');
$CI->email->to($to);
$CI->email->subject($subject);
$CI->email->message($message);
if($attachfile!=''){
$CI->email->attach($attachfile);
}
当我发送电子邮件时,我希望发件人地址为' companyadmin@company.com'。但它始终使用SMTP邮件地址。
from: Company Admin <mymailid@gmail.com>
reply-to: Company Admin <companyadmin@company.com>
to: reciepient@email.com
date: Sat, Mar 14, 2015 at 5:33 PM
subject: New password
mailed-by: gmail.com
signed-by: gmail.com
为什么我的邮件ID显示在发件人地址中。我怎样才能收到来自mailID的邮件
答案 0 :(得分:1)
那是因为你使用谷歌smtp和smtp ID。如果您不想在那里使用它,只需使用codeigniter的默认邮件程序,它依赖于您的Web主机的邮件功能:
$this->load->helper('typography');
//Send user information and message to the administrator`s email
$data['Message'] = nl2br_except_pre($message);
$HTML_Message = $this->load->view('email_html_format', $data, true);
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('companyadmin@company.com', 'Company Admin');
$this->email->reply_to('companyadmin@company.com', 'Company Admin');
$this->email->to($to);
$this->email->subject($subject);
$this->email->message($HTML_Message);
$this->email->set_alt_message(nl2br_except_pre($message));
if($attachfile!=''){
$this->email->attach($attachfile);
return $this->email->send();