javascript - 我有一个 HTML 表单,它使用 POST 请求和 PHP 文件自动向我发送电子邮件,但它不起作用……有什么建议吗?
问题描述
我有一个表单,它使用 HTML 表单、http post 请求和 PHP 后端来自动向我发送用户输入表单的数据。提交按预期工作,但我没有收到电子邮件。我的电子邮件也是由 Outlook 运行的。不确定它是否是加密的东西。
HTML 代码
<form action="mail.php" method="POST">
<div class="email-box">
<input class="tbox" id="email_box" name="email" type="email" style="cursor: pointer;" placeholder="Enter your email">
<button class="btn" id="email_btn" type="submit" name="button">Subscribe</button>
</div>
</form>
<!-- Snipped JavaScript validation -->
PHP
<?php
$errors = '';
$myemail = 'me@website.com';
if (empty($_POST['email'])) {
$errors .= "\n Error: all fields are required";
}
$email_address = $_POST['email'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address)) {
$errors .= "\n Error: Invalid email address";
}
if (empty($errors)) {
$to = $myemail;
$email_subject = "New Vrify subscription: $email_address";
$email_body = "You have a new subscriber. " .
"Here are the details:\n Email: $email_address \n " .
$headers = "From: subscriber@website.com";
mail($to, $email_subject, $email_body, $headers);
//redirect to the 'thank you' page
header('Location: thank-you.html');
}
?>
解决方案
这可能不是完整的解决方案,但据我所知
"New Vrify subscription: $email_address"
是无效的。相反,使用.
运算符连接它们
"New Vrify subscription:".$email_address
对您拥有的其他变量执行相同的操作,我在处理以下 php 时遇到了同样的问题:
if (($_SERVER["REQUEST_METHOD"] ?? 'GET') == "POST") {
$msg ="New message from mysite!\n".$_POST["message"]."\nReply Email:".$_POST["email"];
mail("me@gmail.com", time(), $msg,"From: contact@mysite");
}
推荐阅读
- haskell - Haskell IO 递归(带二叉树)
- c++ - linux ipc. Why is msgrcv always blocking?
- c - 在 scanf("%d \n %d") 中扫描两个整数时,\n 有什么用?
- javascript - 使用 JavaScript 函数与 HTML 音频对象交互
- javascript - 从复杂的 DOM 结构中抓取文本
- gdb - ELF 文件中的可变大小与 GDB 报告的大小不同?
- c++ - 在 C++ 上创建指针时如何删除错误?在这种情况下,我必须使用原始指针
- java - 为什么纹理没有加载?我的世界 15.2 锻造 31.2
- java - 如何清理 HiveMQ 消息缓存目录?
- c# - 使用 findcontrol 在 gridview 中查找值并将其与数据库中的数据进行比较