0

Hey there I wrote yesterday about my PHP script and I got the MAMP setup, so my php can run local. The problem is. When I type everything in my contact form and press "send" it executes the code and goes to the "success" html. But i never receive any mail. Is it because I run it locally?

my 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>

my 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
}
?>
Mikkel Madsen
  • 347
  • 2
  • 5
  • 17

2 Answers2

0

You will have to update your SMTP settings in the php.ini file, as suggested here. Or upload it to a server. It should work out of the box there...

Community
  • 1
  • 1
pudelhund
  • 512
  • 2
  • 4
  • 16
  • mail function] ; For Win32 only. ;SMTP = localhost ;smtp_port = 25 ; For Win32 only. ;sendmail_from = my_email@gmail.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). sendmail_path =/usr/sbin/sendmail -t -i -f my_email@gmail.com – Mikkel Madsen Jul 31 '13 at 09:34
  • On a blog they said this would work... So that you can send emails to your gmail etc etc via the local host – Mikkel Madsen Jul 31 '13 at 09:34
0

Email not working on local machine and if your server is windows then may be you have to configure SMTP settings also.

Bindiya Patoliya
  • 2,726
  • 1
  • 16
  • 15