0

您好,我正在解决我的表单发送到电子邮件的问题。我创建了一个表单来向我的电子邮件发送值,当按下发送按钮时,它告诉我消息已发送,但我在雅虎或 gmail 电子邮件中看不到,我什么也没收到......

这是我的 php 代码表单:

<?php 
$ToEmail = 'mr_sergios@yahoo.com'; 
$EmailSubject = 'Site contact form'; 
 $mailheader = "From: ".$_POST["email"]."\r\n"; 
 $mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
 $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"].""; 
$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 
  mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?>

<?php 
if ($_POST["email"]<>'') { 
$ToEmail = 'mr_sergios@yahoo.com'; 
$EmailSubject = 'Site contact form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"].""; 
$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 
?> 
   Your message was sent
      <?php 
   } else { 
  ?> 
    <form action="test.php" method="post">
   <table width="400" border="0" cellspacing="2" cellpadding="0">
  <tr>
     <td width="29%" class="bodytext">Your name:</td>
  <td width="71%"><input name="name" type="text" id="name" size="32"></td>
    </tr>
    <tr>
     <td class="bodytext">Email address:</td>
    <td><input name="email" type="text" id="email" size="32"></td>
     </tr>
      <tr>
   <td class="bodytext">Comment:</td>
        <td><textarea name="comment" cols="45" rows="6" id="comment"  
  class="bodytext">      
   </textarea></td>
  </tr>
  <tr>
   <td class="bodytext"> </td>
    <td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
    </tr>
       </table>
   </form> 
 <?php 
  }; 
  ?>
4

4 回答 4

0

你是从 Linux 发送的吗?如果是,请检查/var/log/mail.errSMTP 是否抛出任何错误。

对于 Windows,可能需要安装 SMTP 服务器,例如 Mercury SMTP

于 2013-03-09T17:05:28.387 回答
0

您可能没有在php.ini. 我建议使用其他东西mail(),因为它更有可能是可靠的。试试这样的东西

要么,要么它只是落在您的垃圾邮件文件夹中。

于 2013-03-09T17:04:11.100 回答
0

您是否考虑过使用PHP Mailer 类?

下面的示例是在同一页面上提交给自身的表单,只需将以下内容粘贴到您的联系页面的最顶部。下载并包含您的课程。

require_once('class.phpmailer.php');
$address = "you@youremail.com";
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$subject = htmlspecialchars($_POST['subject']);
$comment = htmlspecialchars($_POST['comment']);

$mail  = new PHPMailer(); // defaults to using php "mail()"
$body = $comment;
$mail->AddReplyTo($email,$name);
$mail->SetFrom($email,$name);
$mail->AddReplyTo($email,$name);
$mail->AddAddress($address, "Your Name");
$mail->Subject = $subject;
$mail->MsgHTML($body);
if(isset($_POST['submit']))
{
$mail->Send();
}
于 2013-03-09T17:10:34.830 回答
0

考虑使用这个库:http ://code.google.com/a/apache-extras.org/p/phpmailer/

它非常易于设置和使用,还会在出现错误时为您提供详细信息。

于 2013-03-09T17:10:42.677 回答