javascript 在Html中不打开电子邮件客户端的电子邮件表单

bzzcjhmw  于 2022-11-20  发布在  Java
关注(0)|答案(1)|浏览(126)

我试图在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>
zlhcx6iw

zlhcx6iw1#

是的,你可以发送一封电子邮件,而不需要打开像gmail和outlook这样的客户端,但你需要和smtp服务器来做到这一点。你可以得到gmail的smtp凭据,这是用户名:your-email-id@gmail.com和密码:创建一个应用程序passwsord。然后你可以通过php或python发送电子邮件使用php-mailer与以下代码
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 PHPMailer\PHPMailer\PHPMailer;
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";
    }
}

相关问题