0

嘿,我昨天写了关于我的 PHP 脚本的文章,并且我得到了 MAMP 设置,所以我的 php 可以在本地运行。问题是。当我在我的联系表格中输入所有内容并按“发送”时,它会执行代码并转到“成功”html。但我从来没有收到任何邮件。是因为我在本地运行它吗?

我的html:

<h2>Kontakt os</h2>

<form class="form" name="contactform" method="post" action="php/send_form_email.php">

<p class="name">
<input  type="text" name="first_name" maxlength="50" size="30" placeholder="Fornavn:">
<label for="first_name"></label>
    </p>

    <div class="seperator1"></div>

    <p class="lastname">
 <input  type="text" name="last_name" maxlength="50" size="30" placeholder="Efternavn:">
        <label for="last_name"></label>     
    </p>

    <div class="seperator1"></div>

    <p class="email">
<input  type="text" name="email" maxlength="80" size="30" placeholder="Email:">
        <label for="email"></label>
    </p>

    <div class="seperator1"></div>

    <p class="phone">
<input  type="text" name="telephone" maxlength="30" size="30" placeholder="Tlf:">
        <label for="telephone"></label>
    </p>

    <div class="seperator1"></div>

    <p class="text">
        <textarea name="textbox" placeholder="Skriv til os her" /></textarea>
        <label for="textbox"></label>
    </p>

    <p class="submit">
        <input type="submit" value="Submit">
    </p>

</form>

我的PHP:

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

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "im_using_a_gmail@gmail.com";
$email_subject = "Mysole";


function died($error) {
    // your error code can go here
    echo "Undskyld, men det ser ud til der er sket en fejl.";
    echo "Fejl står nedeunder.<br /><br />";
    echo $error."<br /><br />";
    echo "Gå venligst tilbage for at rette fejlen.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['textbox'])) {
    died('Undskyld, men det ser ud til der er sket en fejl.');       
}

$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$textbox = $_POST['textbox']; // 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 .= 'Forkert email adresse.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Forkert fornavn.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Forkert efternavn.<br />';
}
if(strlen($textbox) < 2) {
$error_message .= 'Den tekst du har skrevet er ikke gyldig.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

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

$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Textbox: ".clean_string($textbox)."\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 -->
Tak fordi du sendte os en besked, vi vil vende tilbage hurtigst muligt.

<a href="../index.php">klik her</a> for at komme tilbage til forsiden.

<?php
}
?>
4

2 回答 2

0

电子邮件在本地计算机上不起作用,如果您的服务器是 Windows,那么您可能还必须配置 SMTP 设置。

于 2013-07-31T09:25:17.047 回答
0

您必须按照此处的建议更新 php.ini 文件中的 SMTP 设置。或者上传到服务器。它应该在那里开箱即用......

于 2013-07-31T09:24:35.010 回答