无法以此联系表格发送电子邮件
问题描述:
我已使用我的联系表单完成,但收到错误消息显示“无法发送”。我有一个展示没有错误,除了发送邮件的线路是:无法以此联系表格发送电子邮件
$isSuccess = mail($to, $subject, $message, $headers);
而且,我已经修改了代码,根据论坛成员的建议,仍然我收到了同样的错误。
可以帮我吗?我也读过PHP文档,我遵循所有的指示,但仍然没有结果。
HTML代码:
<!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">
\t First Name:<input type="text" name="fname"><span style="color: red" >*</span><br><br>
\t Last Name:<input type="text" name="lname"><span style="color: red" >*</span><br><br>
\t E-mail:<input type="text" name="email"><span style="color: red" >*</span><br><br>
\t Telephone:<input type="text" name="tel"><br><br>
\t Designation:<select name="design">
\t \t <option value="Architectural Engineer">Architectural Engineer</option>
\t \t <option value="Structural Engineer">Structural Engineer</option>
\t \t <option value="Draughts-man">Draughts-man</option>
\t \t <option value="Receptionist">Receptionist</option>
\t \t <option value="Secertary">Secertary</option>
\t </select><br><br>
\t Country Applied From:<select name="country">
\t \t <option value="">Country...</option>
\t \t <option value="Afganistan">Afghanistan</option>
\t \t <option value="Albania">Albania</option>
</select><br><br>
\t Message:<textarea name="comment"></textarea> <br><br>
\t Upload Your Resume:<span style="color: red" >*</span><input type="file" name="uploaded_file"><br><br> \t
\t <input type="submit" name="submit" value="Submit">
\t <input type="reset" value="Clear">
</form>
</body>
</html>
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 = '[email protected]';
$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...";
}
}
?>
答
我已经发现的@amanrawat帮助其是本地的虚拟主机上安装的邮件服务器解决方案而不是PHP邮件程序有一种比测试邮件服务器工具更容易的方式,您可以在此链接中查看相关信息:
https://www.youtube.com/watch?v=FSpkJl_YCOE&t=279s
感谢所有帮助过我的人。
你似乎有一个类型*之前*你发送....因为你不关闭你的'$头'值...有更多的东西:'$ headers =“From:”。$ email 。“\ n”;' – Nytrix
如果你使用本地主机检查这个http://stackoverflow.com/questions/18288007/php-send-mail-from-localhost –
@AmanRawat非常感谢你的帮助它现在的作品,现在我欣赏你的帮助非常感谢你 – paulrf