Contact us mail error

心不动则不痛 提交于 2019-12-13 11:25:21

问题


My html coding for the contact form html page and below that is the php code

<form name="form1" method="post" action="contact.php" id="contactform">
                                <table width="100%" border="0" cellspacing="1" cellpadding="3">
                                    <tr>
                                        <td><input name="name" type="text" id="name" ONFOCUS="clearDefault(this)" value="Name" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td>
                                    </tr>
                                    <tr>
                                        <td><input name="customer_mail" type="text" value="Email" ONFOCUS="clearDefault(this)" id="customer_mail" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td>
                                    </tr>
                                    <tr>
                                        <td width="82%"><input name="subject" type="text" value="Subject" ONFOCUS="clearDefault(this)" id="subject" size="90" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px; height: 25px;"></td>
                                    </tr>
                                    <tr>
                                        <td><textarea name="detail" cols="90" rows="8" id="detail" style="background: #DAEDFF; border:1px solid #DAEDFF; border-radius:3px;"></textarea></td>
                                    </tr>
                                    <tr>
                                        <td style="padding-left: 530px;"><input type="submit" name="Submit" value="Send" style="background: #1B99E8; border: 1px solid #1B99E8; color: #ffffff; border-radius:3px;"></td>
                                    </tr>
                            </table>
                        </form>

contact.php file

<?php

$subject        =   $_POST['subject'];
$detail         =   $_POST['detail'];
$customer_mail  =   $_POST['customer_mail'];
$name           =   $_POST['name'];

// Contact subject
$subject ="$subject"; 

// Details
$message="$detail";

// Mail of sender
$mail_from="$customer_mail"; 

// From 
$header="from: $name <$mail_from>";

// Enter your email address
$to ='it@reverseinformatics.com';
$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo '<script language="javascript">confirm("We have received your request, our team will contact you shortly.")</script>';
echo '<script language="javascript">window.location = "contact.html"</script>';
}
else {
echo '<script language="javascript">confirm("Oops Sorry for the inconvinience.")</script>';
echo '<script language="javascript">window.location = "contact.html"</script>';
}
?>

Above is my code plz help me to overcome my problem since i have hosted in the site, it works well in my local server but not working in the website


回答1:


I guess thee is problem with your code at window.location = "contact.html" part. If you want to redirect to this page, try giving absolute path. You may also try window.location.href or window.open. Note that window.open will open it in new window.




回答2:


You also have a very common error a lot of people have with "Contact Us" forms.

// Mail of sender
$mail_from="$customer_mail"; 

This will break SPF and also cause DMARC to fail and you will never get the message from some people, if your mail server you use has DMARC enabled on it.

Since DMARC is a more recent protocol, a lot of the old cookie cutter code for contact us forms - doesn't take this into account.

You can read more about that here: "DMARC - Contact Form Nightmare"

The suggested workaround will be to do:

$mail_from='it@reverseinformatics.com';
$subject ="$subject" .  $_POST['customer_mail']; 

This way - you avoid the issue outline in the article. You won't quickly be able to hit the "Reply" button, but at least you'll get the emails from those customers who have DMARC enabled.



来源:https://stackoverflow.com/questions/16539566/contact-us-mail-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!