skip to Main Content

This is my code:

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

$to = '[email protected]';  
$subject = 'Test Sending';
$message = 'This is Test    for sending Mail';
$header = 'Content-type: text/plain; charset="utf-8"' . "rn" .
                    'From: [email protected]' . "rn" .
                    'Replt-To: [email protected]' . "rn";

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

and this HTML code:

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

My host is on Parallel Plesk… But the mail did not send to…

What’s my problem? Have You any Idea or Suggestion For me?

this is full code:

<!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 = '[email protected]';  
$subject = 'Test Sending';
$message = 'This is Test    for sending Mail';
$header = 'Content-type: text/plain; charset="utf-8"' . "rn" .
                    'From: [email protected]' . "rn" .
                    'Reply-To: [email protected]' . "rn";

$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>

2

Answers


  1. Try putting

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

    At the top of your PHP code.

    Also, replace

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

    with

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

    because $mailsent is not a string you shouldn’t try and echo it.

    It may also help to make a php_info() file and check the mail parameters.

    Login or Signup to reply.
  2. Try this, your headers are funky. Tested this and it works.

    <?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 = "[email protected]";
            $to = '[email protected]';  
            $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>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search