开发者

How to fix these errors in my Email Contact Form PHP?

I have never code in PHP before and I am having trouble with my Email contact form. I got this email form from http://www.freecontactform.com/email_form.php and I have made some few changes with the text only, not the code.

Below is that I have inside the HTML file.

<form name="contactform" method="post" action="send_form_email.php">
                            <table width="450px">
                                <tr>
                                 <td valign="top">
                                  <label for="first_name">Nama Depan*</label>
                                 </td>
                                 <td valign="top">
                                  <input  type="text" name="first_name" maxlength="50" size="50">
                                 </td>
                                </tr>

                                <tr>
                                 <td valign="top">
                                  <label for="last_name">Nama Belakang*</label>
                                 </td>
                                 <td valign="top">
                                  <input  type="text" name="last_name" maxlength="50" size="50">
                                 </td>
                                </tr>

                                <tr>
                                 <td valign="top">
                                  <label for="email">Email Address*</label>
                                 </td>
                                 <td valign="top">
                                  <input  type="text" name="email" maxlength="80" size="50">
                                 </td>
                                </tr>

                                <tr>
                                 <td valign="top">
                                  <label for="telephone">Nomor Telepon</label>
                                 </td>
                                 <td valign="top">
                                  <input  type="text" name="telephone" maxlength="30" size="50">
                                 </td>
                                </tr>

                                <tr>
                                 <td valign="top">
                                  <label for="comments">Koment/Pesan*</label>
                                 </td>
                                 <td valign="top">
                                  <textarea  name="comments" maxlength="1000" cols="38" rows="6"></textarea>
                                 </td>
                                </tr>

                             <tr>
                                 <td colspan="2" style="text-align:center">
                                  <br/><br/>
                                  <input type="submit" value="Submit">   <a href="http://www.freecontactform.com/email_form.php">Email Form</a>
                                 </td>
                                </tr>
                            </table>
                        </form>

Below is what I have inside the PHP file that is responsible for sending the email.

<?php
if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "sammydhenny@gmail.com开发者_运维技巧";
    $email_subject = "Customer Service";


    function died($error) {
        // your error code can go here
        echo "Kami mohon maaf, tapi ada kesalahan ditemukan dengan formulir yang Anda kirimkan.";
        echo "Kesalahan ini muncul di bawah.<br /><br />";
        echo $error."<br /><br />";
        echo "Harap kembali dan memperbaiki kesalahan ini.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('Mohon maaf, tapi tampaknya ada masalah dengan formulir yang Anda kirimkan.');      
    }

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'Alamat Email Anda masukkan tidak valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'Nama Pertama Anda masukkan tidak valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'Nama Belakang Anda masukkan tidak valid.<br />';
  }
  if(strlen($comments) < 2) {
    $error_message .= 'Komentar Anda masukkan tidak valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Formulir rincian di bawah.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Nama Depan: ".clean_string($first_name)."\n";
    $email_message .= "Nama Belakang: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telepon: ".clean_string($telephone)."\n";
    $email_message .= "Komentar: ".clean_string($comments)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- include your own success html here -->

Terima kasih telah menghubungi kami. Kami akan menghubungi Anda secepatnya.

<?php
}
?>

Sorry that I don't use English in the sentences, I want to use this contact form for my dad's company in oversea. Below are the errors that I get:

"; echo $error."

"; echo "Harap kembali dan memperbaiki kesalahan ini.

"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('Mohon maaf, tapi tampaknya ada masalah dengan formulir yang Anda kirimkan.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'Alamat Email Anda masukkan tidak valid.
'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'Nama Pertama Anda masukkan tidak valid.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'Nama Belakang Anda masukkan tidak valid.
'; } if(strlen($comments) < 2) { $error_message .= 'Komentar Anda masukkan tidak valid.
'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Formulir rincian di bawah.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Nama Depan: ".clean_string($first_name)."\n"; $email_message .= "Nama Belakang: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telepon: ".clean_string($telephone)."\n"; $email_message .= "Komentar: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Terima kasih telah menghubungi kami. Kami akan menghubungi Anda secepatnya.

I think the error might be in the syntax, but I don't know where since I don't understand PHP at all.

Thank you so much in advance.


It's likely that your php is not working correctly, either because it's not activated or malconfigured, that I cannot know. can you run a simple script like

?php
phpinfo();
?>

?

anyway, this is what's happening: when you submit your form to the send_form_email.php, this file is rendered AS IS in your html.

and it happens that

<?php
if(isset($_POST['email'])) {

is interpreted as a STARTING HTML TAG, which ends at the first ending tag (for the browser) encountered, that is in this line:

echo "Kesalahan ini muncul di bawah.<br /><br />";

And the same mechanism happens every < and > the browser sees. Et voilà, your result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜