gpt4 book ai didi

JavaScript 告诉谁发送了电子邮件,但我没有收到

转载 作者:行者123 更新时间:2023-12-03 08:47:49 25 4
gpt4 key购买 nike

你好,我是 php 和 web 设计的菜鸟,英语不是我的母语,所以请原谅我的拼写或语法错误。

我正在做一个关于竞争性编程的项目

我制作了一个表格: http://takmicarskoprogramiranje.comuf.com/kontakt.html

正如您所看到的,当您发送消息时,javascript 会提醒电子邮件已发送,但我在电子邮件中没有收到它(contact.php 位于同一文件夹中,托管站点已安装 php)

以下是 html 和 php 的代码:HTML

<form action="contact.php" method="post">
Your name<br>
<input type ="text" name ="cf_name"><br>
Your e-mail<br>
<input type ="text" name ="cf_email"><br>

Message<br>
<textarea name = "cf_message"></textarea><br>

<input type="submit" value ="Send">
<input type="reset" value="Reset">
</form>

PHP:

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'takmicarsko.programiranje@yahoo.com';
$subject = 'Poruka od posjetioca site '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'kontakt.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to takmicarsko.programiranje@yahoo.com');
window.location = 'kontakt.html';
</script>
<?php
}
?>

最佳答案

在电子邮件标题发件人中应包含您的电子邮件。不是用户电子邮件

$headers = "From: mail@takmicarskoprogramiranje.comuf.com\r\n";

更新

添加以下 header

$headers = "Content-type:text/plain" . "\r\n";

所以它应该看起来像这样

$headers = "Content-type:text/plain" . "\r\n";
$headers .= "From: mail@takmicarskoprogramiranje.comuf.com\r\n";

最终

<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'takmicarsko.programiranje@yahoo.com';
$subject = 'Poruka od posjetioca site '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = "Content-type:text/plain" . "\r\n";
$headers .= 'From: mail@takmicarskoprogramiranje.comuf.com\r\n';
$headers .= 'Reply-To: mail@takmicarskoprogramiranje.comuf.com\r\n';
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if (!$mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to takmicarsko.programiranje@yahoo.com');
window.location = 'kontakt.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'kontakt.html';
</script>
<?php
}
?>

关于JavaScript 告诉谁发送了电子邮件,但我没有收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32812639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com