我已完成联系表单,但收到错误消息“无法发送”。除了发送邮件的行外,我没有显示错误:
$isSuccess = mail($to, $subject, $message, $headers);
此外,我已根据论坛成员的建议修改了代码,但仍然收到同样的错误。
可以帮助我吗?我也阅读了PHP文档,我遵循了所有说明,但仍然没有结果。
HTML code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<h2>Contact Form</h2>
<p><span style="color: red" >*Required field</span></p>
<form action="contact.php" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
First Name:<input type="text" name="fname"><span style="color: red" >*</span><br><br>
Last Name:<input type="text" name="lname"><span style="color: red" >*</span><br><br>
E-mail:<input type="text" name="email"><span style="color: red" >*</span><br><br>
Telephone:<input type="text" name="tel"><br><br>
Designation:<select name="design">
<option value="Architectural Engineer">Architectural Engineer</option>
<option value="Structural Engineer">Structural Engineer</option>
<option value="Draughts-man">Draughts-man</option>
<option value="Receptionist">Receptionist</option>
<option value="Secertary">Secertary</option>
</select><br><br>
Country Applied From:<select name="country">
<option value="">Country...</option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
</select><br><br>
Message:<textarea name="comment"></textarea> <br><br>
Upload Your Resume:<span style="color: red" >*</span><input type="file" name="uploaded_file"><br><br>
<input type="submit" name="submit" value="Submit">
<input type="reset" value="Clear">
</form>
</body>
</html>
&#13;
PHP代码:
<?php
if(isset($_POST['submit']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$design = $_POST['design'];
$country = $_POST['country'];
$comment = $_POST['comment'];
$to = 'eng.bolaraafat@hotmail.com';
$subject = 'Contact Form';
$message = 'From: '.$fname .$lname."\r\n";
'E-mail: '.$email."\r\n";
'Telephone: '.$tel."\r\n";
'Designation: '.$design."\r\n";
'Country Appled From: '.$country."\r\n";
'Message: '.$comment."\r\n";
$headers = "From:" .$email. "\n" .
$isSuccess = mail($to, $subject, $message, $headers);
if( $isSuccess == true ) { // if mail is successfully sent
echo "Message sent successfully...";
}else{
echo "Message could not be sent...";
}
}
?>
答案 0 :(得分:0)
我在@amanrawat的帮助下找到了一个解决方案,它在本地Web主机上安装邮件服务器,而不是PHP邮件程序,有一种方法比测试邮件服务器工具更容易,你可以从这个链接中遵循以下方法:
https://www.youtube.com/watch?v=FSpkJl_YCOE&t=279s
感谢所有帮助过我的人。