145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

Hi,

I have taken parts of the code from a tutorial two months ago and it worked. Now I tried my Contact Page again (online. not on a local server) and I don’t get any Emails anymore.

I always get the text message “Thank you for your mail…” I also get in the “if(!isset($hasError)) {” (tried it with an echo).

Also tried it with just this code inside the isset and didn’t work
$emailTo = "example@example.com";
wp_mail('example@example.com', 'subject', 'message');

Here’s the code (without the contact form):

$nameError ="";
$emailError ="";
$commentError ="";

if(isset($_POST['submitted'])) {
    if(trim($_POST['contactName']) === '') {
        $nameError = ' <span class="errormessage">'.__('Please enter your Name.','LovelessDesign').'</span>';
        $hasError = true;
    } else {
        $name = trim($_POST['contactName']);
    }

    if(trim($_POST['email']) === '')  {
        $emailError = ' <span class="errormessage">'.__('Please enter your Email Address.','LovelessDesign').'</span>';
        $hasError = true;
    } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
        $emailError = ' <span class="errormessage">'.__('You entered an invalid Email Address.','LovelessDesign').'</span>';
        $hasError = true;
    } else {
        $email = trim($_POST['email']);
    }

    if(trim($_POST['comments']) === '') {
        $commentError = ' <h5><span class="errormessage">'.__('Please enter a Message.','LovelessDesign').'</span></h5>';
        $hasError = true;
    } else {
        if(function_exists('stripslashes')) {
            $comments = stripslashes(trim($_POST['comments']));
        } else {
            $comments = trim($_POST['comments']);
        }
    }

    if(!isset($hasError)) {
        $emailTo = ot_get_option( 'contact_email' );
        if (!isset($emailTo) || ($emailTo == '') ){
            $emailTo = get_option('admin_email');
        }
        $subject = __('Contact Form, from ','LovelessDesign').$name;
        $body = "Name: $name \nEmail: $email \n\nComments: $comments";
        $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

        wp_mail($emailTo, $subject, $body, $headers);
        $emailSent = true;
    }
} 

....
<?php if(isset($emailSent) && $emailSent == true) { ?>

     <h3><?php _e('Thank you for your Email.','LovelessDesign'); ?></h3>
     <?php _e('We have received your message and will respond as soon as possible.','LovelessDesign'); ?>

<?php } else {

....

Any Ideas?

Thanks

894 posts
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Grew a moustache for the Envato Movember competition
infuse01 says

Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.

Try Contact Form 7 – create some custom forms and style the output according to the overall design. :D

707 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
ChillThemes says


Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.
Terrible advice.

How is that terrible advice? Care to explain? Just support Contact Form 7 and/or Gravity Forms and save yourself some time. Plugins were made for a reason, don’t be afraid to support them. Just include a list of recommended plugins in your documentation, that’s what I do for shortcodes, etc.

114 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Has been a member for 2-3 years
  • Italy
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
mountainthemes says
How is that terrible advice? Care to explain? Just support Contact Form 7 and/or Gravity Forms and save yourself some time. Plugins were made for a reason, don’t be afraid to support them. Just include a list of recommended plugins in your documentation, that’s what I do for shortcodes, etc.

+1

894 posts
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Grew a moustache for the Envato Movember competition
infuse01 says

I wouldn’t recommend using wp_mail. Try this:
<? if($_SERVER['REQUEST_METHOD'] == "POST" ) {

    $destination = 'john@doe.com'; // change this to your email.

    // ##################################################
    // DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING
    // ##################################################

    $email   = $_POST['email'];
    $name     = $_POST['contactName'];
    $message = $_POST['comments'];
    $subject = $name;
    $headers = "From: ".$name." <".$email.">\r\n" .
             "Reply-To: ".$name." <".$email.">\r\n" .
             "X-Mailer: PHP/" . phpversion() . "\r\n" .
             "MIME-Version: 1.0\r\n" .
             "Content-Type: text/plain; charset=\"iso-8859-1\r\n" .
             "Content-Transfer-Encoding: 8bit\r\n\r\n";

    mail($destination, $subject, $message, $headers);

}

Yeah I have an idea: Simply stop embedding your contact forms into your themes and try better to support existing form plugins since “forms” shouldn’t be part of themes and you’re always limited (and you limit your clients too) with the customization of those forms.
Terrible advice.

Based on your advice it seems pretty much that you doesn’t care about Wordpress and its core functions. So I wouldn’t expect any different answer from someone like you…

2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
revaxarts says

Have to agree with infuse. Your version is bad coding and open for injections. wp_mail is much better if you use WordPress

145 posts
  • Austria
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
LovelessDesign says

Thanks guys. But it also doesn’t work with PHP mail and also not with Contact Form 7. There might be something wrong with my host

by
by
by
by
by
by