PHP电子邮件反馈表

时间:2014-11-25 12:31:47

标签: php html forms submission feedback

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

$mail_to = 'someemail@eample.com';
$subject = 'Feedback from '. $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 your feedback, have a nice day!');
        window.location = 'some undefined location';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Sorry your feedback was not sent, please try again soon!');
        window.location = 'some undefined location';
    </script>
<?php
}

&GT;

我正在尝试创建一个表单,将反馈提交到我想要的电子邮件地址,当我输入所有详细信息但我没有收到任何电子邮件时,表单似乎运行顺畅?

谁能明白为什么?

谢谢!

3 个答案:

答案 0 :(得分:1)

像这样写标题:

$headers = "From: " . $field_email. "\r\n";
$headers .= "Reply-To: ". $field_email. "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

example :

$from = "xyz@zz.com";
$to = "youremail@address.com";
$subject = "subject trail mail";
$mail_msg = "trail mail body";

$headers = "From: "  . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$retval = mail ($to,$subject,$mail_msg,$headers);

if( $retval == true )  
{
    $st = "mail sent successfully";
}
else{
    $st = "mail error" ;
}
echo "mail Status : " . $st ;

答案 1 :(得分:0)

$subject = 'Feedback from '. $field_name

应该是: $subject = 'Feedback from '. $field_name;

答案 2 :(得分:0)

实际上有什么东西在POST吗?如果我用数据替换三个第一个POST,我就可以正确获取邮件。你能否回应你发布的价值?

此代码:

>  <?php $field_name = 'Name'; $field_email = 'name@mail.com';
> $field_message = 'This is the message';
> 
> $mail_to = 'freekgille@gmail.com'; $subject = 'Feedback from '.
> $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 your feedback, have a nice day!');
>     </script> <?php } else { ?>
>     <script language="javascript" type="text/javascript">
>         alert('Sorry your feedback was not sent, please try again soon!');
>     </script> <?php } ?>

结果如下: enter image description here