【问题标题】:Email Form Without Opening Email Client In Html在 Html 中不打开电子邮件客户端的电子邮件表单
【发布时间】:2022-11-20 20:17:18
【问题描述】:

我正在尝试用 html 制作一个页面,我可以在其中有一个表单,当您按下提交时,它会向某人发送一封电子邮件,其中包含表单的输出,而无需打开 gmail、outlook 等电子邮件客户端。

这是我的代码和我尝试过的

<form action="mailto:info@w3docs.com" method="post" enctype="text/plain">
    <div>
      <label for="name">First-Name:
        <input type="text" name="name" id="name" />
      </label>
    </div>

    <div>
        <label for="sname">Surname:
          <input type="text" name="surname" id="name" />
        </label>
      </div>

    <div>
      <label for="email">Email:
        <input type="text" name="email" id="email" />
      </label>
    </div>

    <div>
        <label for="phone-number">Phone Number:
          <input type="text" name="phone-number" id="email" />
        </label>
      </div>

      <label for="Gender">Gender</label>
      <select id="Gender" name="Gender">
        <option value="" disabled selected>Select Your Gender</option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
        <option value="Other">Other</option>
        <option value="Rather Not Say">Rather Not Say</option>
      </select>

      <div>
        <label for="Password">Password:
          <input type="text" name="PS" id="name" />
        </label>
      </div>

    <div>
      <input type="submit" name="submit" value="Send" />
    </div>
  </form>

【问题讨论】:

  • eh。您确实需要一个后端,一个将为您发送该消息的服务器。

标签: javascript html email


【解决方案1】:

是的,您可以在不打开 gmail 和 outlook 等客户端的情况下发送电子邮件,但您需要 smtp 服务器才能做到这一点。您可以获得 gmail 的 smtp 凭据,即用户名:your-email-id@gmail.com 和密码:创建应用程序密码。然后您可以使用带有以下代码的 php-mailer 通过 php 或 python 发送电子邮件

You can download php-mailer through this link https://storage.googleapis.com/aryan-rh-cdn.appspot.com/Public-Uploads/php-mailer_221120_114205.tar

//inlcude php-mailer library
require_once("php-mailer/PHPMailer.php");
require_once("php-mailer/SMTP.php");
require_once("php-mailer/Exception.php");
use PHPMailerPHPMailerPHPMailer;
function sendMail($name, $email, $body, $subject, $date)
{

  $mail = new PHPMailer();
  $mail->isSMTP();
  $mail->Host = "smtp.gmail.com";
  $mail->SMTPAuth = true;
  $mail->Username = "your gmail id";
  $mail->Password = "app specific password";
  $mail->Port = 587;

  $mail->setFrom("your email id":, $name);
  $mail->addReplyTo("reply-to-your-gmail@gmail.com", $name); // reply to address usually not needed
  $mail->addAddress($email);

  $mail->isHTML(false);
  $mail->Subject = $subject;
  $mail->Body = $body;

  if ($mail->send()) {
    $mail_send_status = true;
  } else {
    $mail_send_status = false;
  }
    if ($mail_send_status == true) {
       echo "mail is successfully sent to " . $email;
    }else{
      echo "An error occured while sending email";
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-13
    • 2012-10-17
    • 1970-01-01
    • 2015-09-25
    • 2010-11-13
    • 2023-03-19
    相关资源
    最近更新 更多