【问题标题】:how to use a variable value in my email template that fetch from database如何在我的电子邮件模板中使用从数据库中获取的变量值
【发布时间】:2018-10-24 21:06:37
【问题描述】:

我的电子邮件格式如

$confirmationcode = rand(10, 1000);
$unumber = uniqid();
$message= '<html><head></head><body>
          <div style="height:600px; width:100%; "> 
            <h3>'.$fetch_tration.'<br></div></body> </html>';

        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = 465;
        $config['smtp_user'] = 'example@example.com';
        $config['smtp_pass'] = '************';
        $config['charset'] = 'utf-8';
        $config['wordwrap'] = TRUE;
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->set_newline("\r\n");
        $this->email->from('example@example.com', 'Admin Team');
        $this->email->to(example@example.com);
        $this->email->subject('Confirm  Registration');
        $this->email->message($message);
        $this->email->set_mailtype('html');
        $this->email->send();  

在电子邮件代码中 $fetch_tration 是看起来像的电子邮件模板

请确认您在 www.doamin.Com 的注册

其中确认文本有一个链接,如 http://example.com/mycon/emailconfirmation/'.$confirmationcode.'/'.$unumber.'

我想用邮件时分配的值替换 $confirmationcode 和 $unumber。 当有人注册而不是电子邮件发送成功但变量 $confirmationcode 和 $unumber 未在链接中分配时。当用户点击确认链接时,感谢收到类似的错误

您提交的 URI 包含不允许使用的字符。

请帮忙 提前致谢

【问题讨论】:

    标签: php mysql codeigniter email


    【解决方案1】:

    如果您使用 CodeIgniter 作为您的框架,那么您可以直接从配置文件中允许允许的字符。

    $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-=';
    

    能否请您上传完整链接,这样很容易理解确切的问题。

    http://example.com/mycon/emailconfirmation/'.$confirmationcode.'/'.$unumber.'
    

    如果您将上层链接作为点击按钮,那么这是完全错误的,您必须使用“str_replace”功能从模板中替换网址。

    EXA:

    $emaildata['message'] = file_get_contents(ASSETS_URL.'email_templates/filename');
    $emaildata['message'] = str_replace('ReplacetagName', $YourVariable, $emaildata['message']);
    

    【讨论】:

    • 是的,对于您的电子邮件模板,您可以将变量替换为模板 hatml 标记值。 $emaildata['message'] = file_get_contents(ASSETS_URL.'email_templates/filename'); $emaildata['message'] = str_replace('ReplacetagName', $YourVariable, $emaildata['message']);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    • 2020-12-07
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    相关资源
    最近更新 更多