【问题标题】:Codeigniter PHPMailer how to get the address and mailcontent using inputfields?Codeigniter PHPMailer 如何使用输入字段获取地址和邮件内容?
【发布时间】:2021-02-19 01:59:24
【问题描述】:

所有知道如何使用输入字段获取消息和添加地址的人都好。

public function send()
    {
        $this->load->library('phpmailer_lib');
        try
        {
            $mail=$this->phpmailer_lib->load();
            $mail->setFrom('rayjayabejuela@gmail.com','Rayjay');
            $mail->addAddress('flutterrun@gmail.com'); // I want the input data came from the input fields of email.
 
            $mail->Subject="Subject Matter"; 
            $mailContent=''; I want the input data came from the input fields came from the message.
            $mail->Body=$mailContent;
            
            if($mail->send()){
                echo "Email has been set";
            }
        }
        catch(Exception $e){
            echo $mail->ErrorInfo;
        }
    }

这是我的查看页面页面

<form action="<?php echo base_url(); ?>email/send" method="post">
   <br>
   <input type="email" name="email" class="form-control" placeholder="Enter Email" required>
   <br>
   <textarea name="message" class="form-control" placeholder="Enter message here" required></textarea>
   <br>
   <button type="submit" class="btn btn-primary">Send Message</button>
</form>

【问题讨论】:

  • 你试过$_POST['email'];$this-&gt;input-&gt;post('some_data')吗?
  • 您编写的这个脚本属于一种称为垃圾邮件网关的类型。它允许任何人向他们喜欢的任何人发送任意消息,声称来自您。这是一件非常糟糕的事情,并且可能会导致您的服务器被阻止。如果您想制作联系表格,请查看 PHPMailer 提供的示例,该示例不会遇到这些问题。
  • 是的,先生,我会检查你的 repo github 以获取示例联系表。

标签: codeigniter phpmailer


【解决方案1】:
public function send()
    {
        $this->load->library('phpmailer_lib');
        try
        {
            $email = $this->input->post('email');
            $message = $this->input->post('message');
            
            $mail=$this->phpmailer_lib->load();
            $mail->setFrom('rayjayabejuela@gmail.com','Rayjay');
            $mail->addAddress($email); // I want the input data came from the input fields of email.
 
            $mail->Subject="Subject Matter"; 
            $mailContent=$message; I want the input data came from the input fields came from the message.
            $mail->Body=$mailContent;
            
            if($mail->send()){
                echo "Email has been set";
            }
        }
        catch(Exception $e){
            echo $mail->ErrorInfo;
        }
    }

【讨论】:

    【解决方案2】:

    我会尽力帮助你的。
    您可以从以下位置进行更改:

    $mail->addAddress('flutterrun@gmail.com'); 
    

    到这里:

    $mail->addAddress($_POST['email']); 
    

    您也可以对邮件内容/消息执行此操作。

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2013-11-19
      • 1970-01-01
      • 2020-11-27
      • 2019-06-30
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 2017-09-24
      相关资源
      最近更新 更多