你好我一般都是php和web desing的菜鸟,英语不是我的母亲languange所以请原谅我的拼写或语法错误。
我正在做一个关于竞争性计划的项目
我有一个表格: 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
}
?>
答案 0 :(得分:1)
在电子邮件标题From
中应该有您的电子邮件。不是用户发送电子邮件
$headers = "From: mail@takmicarskoprogramiranje.comuf.com\r\n";
更新
添加以下标题
$headers = "Content-type:text/plain" . "\r\n";
所以看起来应该是这样的
$headers = "Content-type:text/plain" . "\r\n";
$headers .= "From: mail@takmicarskoprogramiranje.comuf.com\r\n";
<强> FINAL 强>
<?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
}
?>