0

我写了这段代码,但它没有发送到我的电子邮件。有什么问题?

这是联系表格中的代码:

<!-- send mail configuration -->
<input type="hidden" value="send-mail.php" name="to" id="to" />
<input type="hidden" value="Enter the subject here" name="subject" id="subject" />
<input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration --> 

这是 send-mail.php 的代码

<?php
//vars
$subject = $_POST['subject'];
$to = explode(',', $_POST['to'] );

$from = $_POST['kurtfarrugia92@gmail.com'];

//data
$msg = "NAME: "  .$_POST['name']    ."<br>\n";
$msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
$msg .= "WEBSITE: "  .$_POST['web']    ."<br>\n";
$msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";

//Headers
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;


//send for each mail
foreach($to as $mail){
mail($mail, $subject, $msg, $headers);
}

?>
4

2 回答 2

0

基本的 PHP 邮件脚本。

文件 mail.php

    <html>
    <body>

    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail("someone@example.com", $subject,
      $message, "From:" . $email);
      echo "Thank you for using our mail form";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='mail.php'>
      Email: <input name='email' type='text'><br>
      Subject: <input name='subject' type='text'><br>
      Message:<br>
      <textarea name='message' rows='15' cols='40'>
      </textarea><br>
      <input type='submit'>
      </form>";
      }
    ?>

    </body>
    </html> 
于 2013-04-10T12:54:32.763 回答
0

你有错误报告吗?获取有关发生/错误的更多信息可能会很方便。

error_reporting(E_ALL);

尝试:

echo "邮件($mail, $subject, $msg, $headers)";

看看您发送给 mail() 的内容是否正是您认为的那样。

于 2013-04-10T12:54:55.043 回答