繁体   English   中英

填写表格后发送 email

[英]send email after filling a form

我正在尝试在 codeigniter 的网站中创建一个功能,以便始终有人填写表格,它将在我的数据库中创建一个条目并发送带有该信息的 email。

现在我已经拥有了一切,所以它进入了数据库,但我需要知道如何发送 email。

<div class="col-md-7 contact-form">
            <form method="post" action="contact" >
                <input placeholder="Assunto" type="text" value="{$nome}" name="nome" >
                <input placeholder="Email" type="text" value="{$email}" name="email" >
                <textarea placeholder="Message" type="text" value="{$content}" name="content"></textarea>
                <input type="submit" value="SEND">
            </form>
        </div>

谢谢你!

您可以使用 phpmailer 库来发送电子邮件

库来源: https://github.com/PHPMailer/PHPMailer

<?php

require 'PHPMailerAutoload.php';

$mail = new PHPMailer;
$mail->isSMTP();                            // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';              // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                     // Enable SMTP authentication
$mail->Username = 'example@gmail.com'; // your email id
$mail->Password = 'password'; // your password
$mail->SMTPSecure = 'tls';                  
$mail->Port = 587;     //587 is used for Outgoing Mail (SMTP) Server.
$mail->setFrom('sendfrom@gmail.com', 'Name');
$mail->addAddress('sendto@yahoo.com');   // Add a recipient
$mail->isHTML(true);  // Set email format to HTML

$bodyContent = '<h1>HeY!,</h1>';
$bodyContent .= '<p>This is a email that Radhika send you From LocalHost using PHPMailer</p>';
$mail->Subject = 'Email from Localhost by Radhika';
$mail->Body    = $bodyContent;
if(!$mail->send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}

?>

您可以使用 CodeIgniter 内置 email 库

Email Class

在您的情况下,我认为最好将“名称”属性赋予提交按钮:

<input type='submit' name='somesubmitbutton' value='SEND' />

然后在发送 email 之前使用它进行验证:

if(!is_null($this->input->post("somesubmitbutton"))){
 $email  = $this->input->post("email");
 $name   = $this->input->post("name");
 $config = [
          'mailtype'  => 'html',
          'charset'   => 'utf-8',
          'protocol'  => 'smtp',
          'smtp_host' => 'smtp.gmail.com',
          'smtp_user' => 'email@gmail.com', // You must turn ON "Allow less secure apps" in this gmail account (open https://myaccount.google.com/lesssecureapps)
          'smtp_pass'   => 'emailpassword',
          'smtp_crypto' => 'ssl',
          'smtp_port'   => 465,
          'crlf'    => "\r\n",
          'newline' => "\r\n"
            ];

 $this->load->library('email',$config);
 $this->email->from('email@gmail.com', 'Sender Name');

 // EMAIL TO
 $this->email->to($email);

 $this->email->subject("Hello!");
 $this->email->message("Good afternoon $name!");
 $this->email->send();
}

暂无
暂无

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

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