-2

ユーザーがデータを紹介して電子メールに送信するフォームを作成しようとしています。

しかし、空白のページ (file.php ページ) に移動し、電子メールが送信されません。

HTML コード:

<form action="./sendmail.php" method="post">
    <div class="log">
        <input type="text" id="name" value="name" name="studname" class="form">
        <input type="email" id="mail" value="mail@gmail.com" name="studmail" class="form">
        <input type="tel" id="age" value="age" class="form" name="studage">
        <input type="submit" value="submit!" id="submit">
    </div>
</form>

そして今、ここに私の「sendmail.php」コードがあります:

<?php
    /*  STUDENT PARAMETERS  */
    $studentName = $_POST['studname'];
    $studentMail = $_POST['studmail'];
    $studentAge = $_POST['studage'];

    mail('code@gmail.com', 'Message',
    'NAME: ' . $studentName . '\nMAIL: ' . $studentMail . '\nAge: ' . $studentAge);
?>

どうすればこれを解決できますか?なぜこれが機能しないのですか? お時間をいただきありがとうございます。

4

3 に答える 3

0

@Telmo Vazはこれを試してください

<?php
    $studentName = $_POST['studname'];
        $studentMail = $_POST['studmail'];
        $studentAge = $_POST['studage'];

    $recipient='code@gmail.com'; 
    $subject="Message"; 
    $content = "New Message Form Contact us\n From: ".$studentName .", \n Email: ".$studentMail .",\n Age: ".$studentAge;
        $headers = 'From: code@gmail.com' . "\r\n" .
        'Reply-To: code@gmail.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
        $retval=mail($recipient, $subject, $content, $headers);
        if( $retval == true ){do something;}
        else{echo "Error Sending Message";}
?>
于 2014-02-27T08:49:48.560 に答える
-2

メールの送信元となるメールアドレスが必要です。メールはこのアドレスから送信されませんが、選択したアドレスが [差出人] セクションに表示されます。これを試して:

/*  STUDENT PARAMETERS  */
$studentName = $_POST['studname'];
$studentMail = $_POST['studmail'];
$studentAge = $_POST['studage'];

$to = "code@gmail.com";
$subject = "Message";
$message = "NAME: " . $studentName . "\nMAIL: " . $studentMail . "\nAge: " . $studentAge;
$from = $to;
$headers = "From:" . $from;

mail($to,$subject,$message,$headers);

echo "Mail Sent.";
于 2013-10-24T22:36:41.103 に答える