-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

我认为你可以使用 phpmailer 类

于 2013-11-03T12:30:13.577 回答
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 回答