Php 无法在我的联系人表单中发送邮件
我设计了一个表单来接收网站访问者的反馈。我已经开发了该网站,但是邮件发送选项无法正常工作。我收到错误“邮件未发送”。谁能帮我解决这个问题 我的Php代码Php 无法在我的联系人表单中发送邮件,php,html,Php,Html,我设计了一个表单来接收网站访问者的反馈。我已经开发了该网站,但是邮件发送选项无法正常工作。我收到错误“邮件未发送”。谁能帮我解决这个问题 我的Php代码 <?php if (isset($_POST['submit'])) { $company=$_POST['company']; $name=$_POST['name']; $email=$_POST['email']; $message=$_POST['message']; $mobile=$_POST['mobile'];
<?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>
帮我解决这个问题
$mail=mail($to,$company,$name,$mobile,$email);
到
邮件只有四个参数(主要是),这就是为什么$mail=mail($to,$company,$name,$mobile,$email)
返回false,您得到了else部分“{echo'Mail is not send';}
”
请检查php邮件函数的参数 试一试
php邮件函数的签名如下 邮件($to、$subject、$body、$additionalHeaders、$additionalParameters) 有关详细信息,请浏览此url
您使用的是本地服务器吗?我在本地服务器和实时服务器上都试过了…它仍然不能工作@SquiroEdit工作正常。但它显示为修剪过的内容。如何避免@squiroidy您需要根据您的要求正确格式化它。教程:-如果答案能解决您的问题,请向上投票并选择答案。
mail($to,$subject,$txt,$headers);
so in your $txt=$company."\n".$name."\n".$email."\n".$message."\n".$mobile;
$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);
$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 :)