-1

just trying to find out why my code is not working. Of course I replaced the mail adress with my valid e-mail. Do you have a clue?

The form seems to work but the problem is, that I do not get any mails in my inbox.

This is the HTML-Part:

        <form id="contact-form">

            <p id="contact-form-success" class="form-success-message column-container align-center">
                <strong><i class="fa fa-check-square-o"></i> Ihre Anfrage wurde verschickt!</strong><br>
                Text Text
            </p>
            <div class="column-container formFields">
            <div class="column one-half"><p><input id="contact-name" class="required" name="contact-name" type="text" placeholder="Vorname"></p>
            <p><input id="contact-name-last" class="required" name="contact-name-last" type="text" placeholder="Nachname"></p>
            </div>
            <div class="column one-half last">
            <p><input id="contact-email" class="required" name="contact-email" type="email" placeholder="E-Mail"></p>
            <p><input id="contact-phone" name="contact-phone" type="tel" placeholder="Telefon (optional)"></p>
            </div>
            </div>
            <br/>
            <p class="submit formFields"><button class="form-submit button grey" type="submit">Angebot anfordern</button></p>
        </form>

The PHP-Part:

<?php

$email = "myname@mail.de";
$subject = "[Auftrag+] Angebot Anfrage";

if ( isset($_POST["contact-name"]) && isset($_POST["contact-name-last"]) && isset($_POST["contact-email"]) ) {

    $name = htmlentities($_POST["contact-name"], ENT_QUOTES, "UTF-8");
    $name_last = htmlentities($_POST["contact-name-last"], ENT_QUOTES, "UTF-8");
    $email = htmlentities($_POST["contact-email"], ENT_QUOTES, "UTF-8");
    $phone = htmlentities($_POST["contact-phone"], ENT_QUOTES, "UTF-8");
    $ip = $_SERVER['REMOTE_ADDR'];
    $to = $email;
    $subject = $subject;
$message = 
<<<HTML
Name: {$name}
Nachname: {$name_last}
Email: {$email}
Phone: {$phone}
IP: {$ip}
HTML;
    $headers = "From:" . $email;
    mail( $to, $subject, $message, $headers );  
    echo "Success";

} else {

    echo "POST request does not contain necessary data!";

}

5 Answers5

0
  1. check what the actual mail command responds:

    echo mail( $to, $subject, $message, $headers );

  2. check you spam if the mail is recieved, you should use the actual from adress that the mail was sent from

BobbyTables
  • 4,481
  • 1
  • 31
  • 39
0

Are you emailing tests to an email account on a service like Gmail by any chance?

If your 'from' domain has an SPF record and the machine you are sending email from isn't one of the designated IP addresses in the domains MX record your emails will be rejected.

If you are sending from a linux box check your mail logs (/var/log/maillog)

detheridge02
  • 640
  • 1
  • 6
  • 18
0

you can print all variable,check whole variable,keep it not null.have a try again. if you meet this problem,you can search more source like SMTP.

0

Your Answer is

Change this <form id="contact-form" method="post">.

In addition

Without checking isset($_POST["aaa"]) use required tag in

<input id="contact-name" class="required" name="contact-name" type="text" placeholder="Vorname" required>

and in submit button set name='submit'

so if that field empty submit button not response. When its Filled its come to the PHP code.

so in that you can easily code using

if(isset($_POST["submit]))
{
  //Your code here
}

try this

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

First Change

<form action="your_action_url" method="post"> I think you forgot to add this

Most of the time the simple mail may fail, mostly the mail will be redirected to spam. To avoid this we need to add the mail headers properly

I guess the following changes will help you.

<?php

$subject = "[Auftrag+] Angebot Anfrage";

if ( isset($_POST["contact-name"]) && isset($_POST["contact-name-last"]) && isset($_POST["contact-email"]) ) {

    $name = $_POST["contact-name"]);
    $name_last = $_POST["contact-name-last"];
    $email = $_POST["contact-email"];
    $phone = $_POST["contact-phone"];
    $ip = $_SERVER['REMOTE_ADDR'];
    $to = $email;
    $subject = $subject;

    $message = "
      Name: ".$name."<br/>
      Nachname: ".$name_last."<br/>
      Email: ".$email."<br/>
      Phone: ".$phone."<br/>
      IP: ".$ip."<br/>";

    $headers .= "Reply-To: The Sender <sender@sender.com>\r\n"; 
    $headers .= "Return-Path: The Sender <sender@sender.com>\r\n"; 
    $headers .= "From: The Sender <senter@sender.com>\r\n";
    $headers .= "Organization: Sender Organization\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n"


    mail( "sender@sender.com", $subject, $message, $headers );  
    echo "Success";

} else {

    echo "POST request does not contain necessary data!";

}
?>

If still the email is not receiving then you can make a try for SMTP mail, which will be more faster and accurate