就像标题所说,将表格发送到我的电子邮件。我没有收到任何错误,但电子邮件从未收到。这是我的 HTML 表单(我认为您不需要任何其他内容,但文件中还有一些格式设置和 Java 验证)。
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label>
<br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label>
<br>
<input type="text" name="email">
<br>
</p>
<p>
<label for='message'>Message:</label>
<br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit">
<br>
</form>
这是我的 PHP。显然,我取出了电子邮件并输入了 EMAIL,但除此之外,这是我完整的 PHP 文件。感谢 PHP 文件很好地提取了提交的页面,并且我没有收到任何错误。只是也没有电子邮件。
<?php
$errors = '';
$myemail = '[email protected]';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
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 = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
提前感谢您提供的任何帮助!如果您需要的话,我可以提供我的 HTML 文件的其余部分或其他 PHP 文件,但这才是所有真正功能所在。
*PHP 将表单数据发送到电子邮件我已经使用了此代码及其对我的工作。您可以尝试*
<?PHP
$email = $_POST["emailaddress"];
$to = "[email protected]";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: [email protected]\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
之后您可以添加更多代码
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)