我想向用户发送邮件,但是当我点击提交按钮时,电子邮件未被发送,我收到一条错误消息,指出未发送请求。这是我的代码,
<?php
include('submit.php');
if(isset($_POST['submit']))
{
extract($_POST);
$to = "chintan.suthar777@gmail.com";
$subject = "Email template";
$message = file_get_contents('index.php');
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: chintan.suthar777@gmail.com";
$mail_sent = mail($to, $subject, $message, $headers);
if($mail_sent)
echo "<script>alert('Thank you. we will get back to you');
window.location='index.php';exit();</script>";
else
echo "<script>alert('Sorry.Request not send');
window.location='index.php';exit();</script>";
}
?>
我的HTML代码如下:
<form name="news_data" action="email.php" method="post" enctype="multipart/form-data">
<table width="100%">
<tbody>
<tr>
<td><h3>News </h3></td><td><input type="text" readonly value="1" name="sec_1_new[]" id="sec_1_new_1" /></td>
</tr>
<tr>
<td>Title of news :</td>
<td><input type="text" name="sec_1_title_news[]" id="sec_1_title_news_1" /><br /><br /></td>
</tr>
<tr>
<td>Description: </td>
<td><textarea rows="5" cols="30" name="sec_1_desc[]" id="sec_1_desc_1" ></textarea><br /><br /></td>
</tr>
<tr>
<td>Title of Link :</td>
<td><input type="text" name="sec_1_newslink[]" id="sec_1_newslink_1" /><br /><br /></td>
</tr>
<tr>
<td>URL of News:</td>
<td><a href="#"><input type="text" name="sec_1_news_url[]" id="sec_1_news_1_url" /><br /><br /></a></td>
</tr>
<tr>
<td>News image:</td>
<td><input type="file" name="sec_1_news_img[][]" id="sec_1_news_1_image" ><br /><br /></td>
</tr>
<tr>
<td></td>
<td align="right"><input class="add" type="button" value="Add" id="sec_1_news_1_add" onClick="add_new(this.id)" /></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="Submit" />
</form>
答案 0 :(得分:0)
检查您的消息是否以&#39;。&#39;开头,因为该消息已被删除,为此使用str_replace("\n.", "\n..", $text);
检查大于70个字符的$ message是否添加$message = wordwrap($message, 70, "\r\n");