1

这是我的代码:

<?php
if ( isset($_POST['send']) ) {
$name = $_POST['name'];

$to = 'kiarash@gmail.com';  
$subject = 'Test Sending';
$message = 'This is Test    for sending Mail';
$header = 'Content-type: text/plain; charset="utf-8"' . "\r\n" .
                    'From: test@site.ir' . "\r\n" .
                    'Replt-To: test@site.ir' . "\r\n";

$mailsent = mail($to, $subject, $message, $header);
echo "this is mail sent---> " . $mailsent;
}
?>

这个 HTML 代码:

<form action="#" method="post" name="frm">
    <input type="text" name="name" />
  <input type="submit" value="send" name="send" />
</form>

我的主机在 Parallel Plesk... 但是邮件没有发送到...

我的问题是什么?你对我有什么想法或建议吗?

这是完整的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if ( isset($_POST['send']) ) {
$name = $_POST['name'];

ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);



$to = 'kiarash@gmail.com';  
$subject = 'Test Sending';
$message = 'This is Test    for sending Mail';
$header = 'Content-type: text/plain; charset="utf-8"' . "\r\n" .
                    'From: info@site.ir' . "\r\n" .
                    'Reply-To: info@site.ir' . "\r\n";

$mailsent = mail($to, $subject, $message, $header);

if($mailsent){
echo "success";
}else{
echo "not sent";
}
}
?>
<form action="#" method="post" name="frm">
    <input type="text" name="name" />
  <input type="submit" value="send" name="send" />
</form>
</body>
</html>
4

2 回答 2

1

试着放

ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);

在 PHP 代码的顶部。

另外,更换

echo "this is mail sent---> " . $mailsent;

if($mailsent){
echo "success";
}else{
echo "not sent";
}

因为$mailsent不是字符串,所以您不应该尝试回显它。

php_info()制作文件和检查邮件参数也可能会有所帮助。

于 2013-09-26T07:27:07.640 回答
1

试试这个,你的标题很时髦。对此进行了测试,并且可以正常工作。

<?php
    ini_set('error_reporting', E_ALL);
    error_reporting(E_ALL);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <?php
    if (isset($_POST['send'])) {
        $name = $_POST['name'];
        $from = "info@site.ir";
        $to = 'kiarash@gmail.com';  
        $subject = 'Test Sending';
        $message = 'You got a message from '. $name;
        $headers = array(
            'MIME-Version: 1.0',
            'Content-Type: text/html; charset="UTF-8";',
            'Content-Transfer-Encoding: 7bit',
            'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
            'From: ' . $from,
            'Reply-To: ' . $from,
            'Return-Path: ' . $from
        );
        $mailsent = mail($to, $subject, $message, implode("\n", $headers));
        if($mailsent){
            echo "success";
        }else{
            echo "not sent";
        }
    }
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="frm">
        <input type="text" name="name" />
        <input type="submit" value="send" name="send" />
    </form>
</body>
</html>
于 2013-09-26T07:42:21.177 回答