繁体   English   中英

添加主题行以在Codeigniter PHP中发送电子邮件

[英]Adding subject line for sending an email in codeigniter php

申请工作需要发送一封电子邮件,其中包含一些详细信息,例如姓名,电话号码,电子邮件,当前ctc等。电子邮件已正确发送,但问题是在主题行中发送电子邮件时,我需要包含名称电子邮件ctc。 。为此,我已经这样做了,但是它不接受这种格式。

        $name = $this->input->post('fullname');
        $email = $this->input->post('email');
        $phone = $this->input->post('mobilenumber');
        $currentemploymentstatus = $this->input->post('current_employment_status');

        //set to_email id to which you want to receive mails
        $to_email = 'yyyy@gmail.com';

        $config=Array(
        'protocol'=> 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
        'smtp_port' => '465', //smtp port number
        'smtp_user' => 'xxxxxx@gmail.com',
        'smtp_pass' => 'PASSWORD123', //$from_email password
        'mailtype' =>'html',
        'newline'  =>"\r\n",
        'crlf' =>"\r\n",
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
        );

        $message            = array();    
        $message[] = 'Fullname  :  '.trim($name).' ';
        $message[] = 'Email :  '.trim($email).' ';
        $message[] = 'Mobile :  '.trim($phone).' ';
        $message[] = 'Current Employment Status :  '.trim($currentemploymentstatus).' ';        

        //$message = implode(PHP_EOL, $message);
        $message = implode('<br>', $message);
        //send mail
        $this->load->library('email',$config);
        $this->email->from($email);
        $this->email->to($to_email);
        //$list = array();
        $this->email->subject($name|$email);
        $this->email->message($message);
        $this->email->set_newline("\r\n");
        $this->email->set_mailtype("html"); 
            if ($this->email->send())
        {
           $this->flash->success('Thank you for applying to this post we will get back to you soon!</div>');
            redirect('apply');
        }
        else
        {
            $this->flash->success('There is error in sending mail! Please try again later');
            redirect('apply');
        }
    }

通过添加此代码即可解决。

$subject = $name .' | '.$currentemploymentstatus .' | '.$expectedctc .' | '.$primaryskills; 
        $this->email->subject($subject);

对于您的问题,请尝试更改“ |” 到。'|'

要清理代码并使生活更轻松:

如果您使用的是CI,请查看我的存储库中有关设置email_model的信息,以简化您使用的代码。 您无需加载库的配置内容,只需击中模型以发送到电子邮件队列,然后再次击中模型以处理队列即可。

https://github.com/ddell003/Email_model

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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