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
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. 
sushipasta said
infuse01 saidTerrible advice.
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.
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.
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
sushipasta said
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); }infuse01 saidTerrible advice.
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.
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…
- Microlancer Beta Tester
- Author had a Free File of the Month
- Has been a member for 3-4 years
- Item was Featured
- Author was Featured
- Austria
- Exclusive Author
- Referred between 200 and 499 users
Have to agree with infuse. Your version is bad coding and open for injections. wp_mail is much better if you use WordPress
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
