我设计了一个表单来接收我的网站访问者的反馈。我开发了网站,但邮件发送选项无法正常工作..我收到错误“邮件未发送”。任何人都可以帮我解决这个问题......
我的Php代码
<?php
if (isset($_POST['submit']))
{
$company=$_POST['company'];
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
$mobile=$_POST['mobile'];
$to='www@gmail.com';
$headers="From: $company";
$mail=mail($to,$company,$name,$mobile,$email);
if($mail) { echo'Mail send successfully'; }
else { echo'Mail is not send'; }
}
?>
这是我的HTML表单
<form id="contact-form" action="" role="form" method="post">
<div class="contact-form-loader"></div>
<fieldset>
<div class="row">
<div class="grid_5">
<label class="company">
<input type="text" name="company" placeholder="Company name" required/>
</label>
<label class="name">
<input type="text" name="name" placeholder="Your name" required/>
</label>
<label class="mobile">
<input type="text" name="mobile" placeholder="Your mobile" required/>
</label>
<label class="email">
<input type="text" name="email" placeholder="Your email" value="" required/>
</label>
</div>
</div>
<div class="row">
<div class="grid_6">
<label class="message">
<textarea name="message" placeholder="Any remarks?"></textarea>
</label>
</div>
</div>
<div class="contact-form-buttons">
<input id="submit" type="submit" name="submit" value="Send" class="sub">
</div>
</fieldset>
</form>
帮我解决这个问题
答案 0 :(得分:2)
更改
$mail=mail($to,$company,$name,$mobile,$email);
到
mail($to,$subject,$txt,$headers);
邮件只有四个参数(主要是)为什么$mail=mail($to,$company,$name,$mobile,$email);
返回false而你得到了其他部分&#34; { echo'Mail is not send'; }
&#34;
so in your $txt=$company."\n".$name."\n".$email."\n".$message."\n".$mobile;
答案 1 :(得分:0)
请检查php邮件功能的参数。
http://php.net/manual/en/function.mail.php
尝试
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail=mail($to,'Your mail subject',$message,$headers);
答案 2 :(得分:0)
php邮件功能的签名就像这样
邮件($到,$主题,$体,$ additionalHeaders,$ additionalParameters);
请详细阅读此网址http://php.net/manual/en/function.mail.php
$to='www@gmail.com';
$headers="From: $company";
/* you have to add email and phone into your message. */
$mail=mail($to,'subject of your mail',$message, $headers);
if($mail) { echo'Mail send successfully'; }
else { echo'Mail is not send'; }
}
?>
try this
Happy coding :)