我想制作一个php代码,提交一些信息发送到我的私人电子邮件地址,我正在寻找的代码是通过电子邮件发送并提交。这是我的代码:
"<div class="form_settings">
<p><span>Navn</span><input class="contact" type="text" name="your_name" value="" /></p>
<p><span>Email Addresse</span><input class="contact" type="text" name="your_email" value="" /></p>
<p><span>Besked</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"></textarea></p>
<p style="padding-top: 15px"><span> </span><input class="submit" type="submit" name="contact_submitted" value="send"></p>
</div>"
答案 0 :(得分:0)
将此插入到您的表单操作所指向的页面上(例如,如果您有,则应将此代码放在send_message.php上:
<?php
if (isset($_POST['your_name']) && isset($_POST['your_email']) && isset($_POST['your_message'])) {
if (!empty($_POST['your_name']) && !empty($_POST['your_email']) && isset($_POST['your_message'])) {
$to = "INSERT THE EMAIL ADDRESS YOU WANT TO SEND TO";
$subject = "SUBJECT";
$name = $_POST['your_name'];
$email = $_POST['your_email'];
$message = "$name sent you a message:"
$message .= "<br><br>" . $_POST['your_message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
if (mail($to,$subject,$message,$headers)) {
header('Location: confirmation.php');
};
};
};
?>
P.S。学习PHP需要时间但值得,youtube有很多好的视频。