使用代码点火器在电子邮件上添加'From'标题



我在CPanel中使用Codeigniter,我的代码已经发送了一封邮件,但当它到达接收方时,主机名会显示在发送方。我尝试了一些问题的答案:更改发件人名称php-mail,而不是sitename@hostname.com但在Codeigniter中,它们不起作用。

这是我的代码:

$config = Array(
'protocol' => 'ssmtp',
'smtp_host' => 'ssl://ssmtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'mail@domainiwant.com', 
'smtp_pass' => 'password',            
'mailtype'  => 'html',
'charset'   => 'iso-8859-1',
'useragent' => 'MY NAME',
);
$this->load->library('email', $config); 
$this->email->set_newline("rn");
$this->email->from('mail@domainiwant.com', 'MY NAME');
$email_to = 'receiver@gmail.com';
$this->email->to($email_to);
$this->email->message('Message testing ...');
$this->email->send();

然而,正如我所说,当邮件到达收件人时,它们会显示主机名和一个完全不同的邮件地址,就像我在$config上放的那个地址一样

我知道这只设置the envelope sender,但我想将邮件地址设置为mail@domainiwant.com,而不是用somemail@host.com.ex接收邮件

根据CodeIgniter电子邮件库的文档,您的整个问题只是一个简单的打字错误。

$config['protocol']允许mailsendmailsmtp作为值。如果你不设置变量,或者使用不允许的值,整个库默认为mail,它试图使用你自己的服务器作为邮件网关(这解释了为什么你的发件人地址显示为username@servername(

将协议从ssmtp更改为smtp,这样您就可以实际使用您想要使用的Google SMTP服务器,并且您将获得预期的结果

最新更新