我的联系表单存在问题,因为它发送的邮件没有发件人信息(名称和电子邮件),也没有邮件。我需要那个。我在我找到的另一篇文章中尝试了var_dump
,但没有奏效。
<form action="form_process.php" class="contact_form" method= "post" onsubmit>
<ul>
<li><label for="name">name:</label><input type="text" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>
<?php
$name = var_dump($_POST['name']);
$email = var_dump($_POST['email']);
$message = var_dump($_POST['message']);
$to = "mmechenique@gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
mail ($to, $subject, $message, "From: " . $name);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
答案 0 :(得分:2)
尝试以这种方式使用您的表单:
<form action="form_process.php" class="contact_form" method= "post">
<ul>
<li><label for="name">name:</label><input type="text" name="name" required /></li>
<li><label for="email">email:</label><input type="email" name="email" required /></li>
<li><label for="message">message:</label><textarea name="message" cols="40" rows="6" required ></textarea></li>
<li><button class="submit" type="submit">Enviar</button></li>
</ul>
</form>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "mmechenique@gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
mail ($to, $subject, $message, "From: " . $name);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
答案 1 :(得分:1)
您的HTML应如下所示:
<form action="form_process.php" class="contact_form" method="post">
<ul>
<li>
<label for="name">name:</label>
<input type="text" name="name" required />
</li>
<li>
<label for="email">email:</label>
<input type="email" name="email" required />
</li>
<li>
<label for="message">message:</label>
<textarea name="message" cols="40" rows="6" required ></textarea>
</li>
<li>
<button class="submit" type="submit">Enviar</button>
</li>
</ul>
</form>
您的PHP应如下所示:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "mmechenique@gmail.com";
$subject = "Nuevo mensaje formulario de contacto";
$headers = "From: Enter something here < email@mail.com >\r\n";
$headers .= "X-Sender: Enter something here < email@mail.com >\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\r\n"; // Urgent message!
$headers .= "Return-Path: email@mail.com\r\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
mail ($to, $subject, $message, $headers);
echo "Tu mensaje ha sido enviado, muchas gracias!";
?>
我不应该如此轻易地给出答案,因为你应该在发布问题之前完成你的研究但是到底是什么。现在你知道下次在发表你的问题之前做一些研究。
修改强>
<?php
$headers = "From: Enter your name < myemail@mail.com >\n"; //If you are the one sending the email enter your name here
OR
$headers = "From: ".$name." < ".$email." >\n"; // If you are the one the email is being sent to then try this header
$headers .= "X-Sender: Enter your name < myemail@mail.com >\n"; //Same logic applies for this guy
OR
$headers .= "X-Sender: ".$name." < ".$email." >\n"; //Same logic applies for this guy
?>