我正在尝试创建一个用户引入数据并将其提交给电子邮件的表单。
然而,它让我到了一个空白页面(file.php页面),并且没有发送电子邮件。
HTML code:
<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);
?>
我该如何解决这个问题,为什么这不起作用?谢谢你的时间。
答案 0 :(得分:0)
我认为你可以使用phpmailer类
答案 1 :(得分: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";}
?>
答案 2 :(得分:-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.";