gpt4 book ai didi

javascript - Node JS 应用程序不处理 php 邮件程序代码

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:49 24 4
gpt4 key购买 nike

我有一个基于 Node JS 框架构建的简单网站,带有 php 邮件程序来处理我的联系表单。我似乎无法让它工作,我想知道 Node JS 本身是否存在无法处理 php 代码的固有问题。它有一个 html 页面,index.html,其中包含联系表单代码:

 <div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<h2 class="featurette-heading" style="text-align: center;">Message</h2>
<h3 class="text-muted">Want to book an appointment? Send me a message and I'll contact you. Make sure you include your name, phone number, email, and when you'd like to book. It's that easy!</h3>
<form name="sentMessage" id="contactForm" action="contact_me.php" method="post" novalidate>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="text" class="form-control" placeholder="Name" id="name" name="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="email" class="form-control" placeholder="Email Address" id="email" name="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<input type="tel" class="form-control" placeholder="Phone Number" id="phone" name="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div style="background-color: white; border: 1px solid #0085a1;" class="row control-group">
<div class="form-group col-xs-12 floating-label-form-group controls">
<label></label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" name="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>

在同一文件夹级别,有一个 contact_me.php 文件:

<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}

$to = 'jcbridwe@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:
$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers = "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>

每当我点击表单底部的“提交”时,我都会收到以下错误:“无法 POST/contact_me.php”。经过一番实验,我在php代码中添加了一条echo语句(我对php的了解非常有限),并确定当 Node 服务器运行时,php似乎没有处理。如果是这种情况,我该怎么做才能解决这个问题?我需要在route.js 或index.js(在Node 的Express Server 文件夹下)中添加一些内容才能使php 邮件程序正常工作?

最佳答案

我学习NodeJS也是如此。为什么你不想使用Nodemailer使用 ExpressJS?它易于使用和设置。

关于javascript - Node JS 应用程序不处理 php 邮件程序代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43524792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com