我已经创建了一个来自我已经尝试了很多PHP代码,我真的厌倦了这个2天,我无法将提交的数据发送到电子邮件,任何人都可以帮我解决这个问题,我我是php新手,但我已经从w3schools(php mail)的代码中尝试了很多次
这是我创建的表单:
<form method="post" action="mail.php">
<table border="0">
<tr><td width="15" class="text"><img src="images/speechbubble.png" width="19" height="20"> Feedback <br /> </td></tr>
<tr><td class="text">Name</td></tr>
<tr><td>
<input type="text" name="Name" required="required" /></td></tr>
<tr><td class="text">Email</td></tr>
<tr><td><input type="email" name="Email" required="required" /></td></tr>
<tr><td class="text">Phone</td></tr>
<tr><td><input type="tel" name="phone" pattern="[0-9]{11}|[0-9]{10}" required></td></tr>
<tr><td class="text">Message</td></tr>
<tr><td><textarea name="Comments" rows="5" cols="20" required></textarea></td></tr>
<tr><td style="text-align:right"> <input type="Submit" value="Submit"/></td></tr>
</table>
</form>
Php:
<?php
$to = "info@appsysinfotech.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $email, $phone, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?>
答案 0 :(得分:0)
在 mail.php 中你必须写下这样的内容:
<php
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['phone'];
$comments = $_POST['Comments'];
if(isset($name, $email, $phone, $comments)) { //check if all fields are set
$message = 'Someone wrote a comment \n'; //
$message .= 'Name: '.$name.'\n'; //
$message .= 'Email: '.$email.'\n'; // Build up the email message
$message .= 'Phone: '.$phone.'\n'; //
$message .= 'Comment: '.$comments.'\n'; //
if(preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/',$email)) { //check if the email address is well written
if(mail('your@email.com', 'Set A Subject', $message)) { //send the email and check if it worked
echo 'email sent succesfully';
}
else { //if it did not work print an error msg
echo 'an error occurred, please try again later';
}
else { //if the email address is invalid print an error msg
echo 'your email address seems to be invalid';
}
else { //if all input fields were not filled print an error msg
echo 'please fill the whole form';
}
?>