Move_uploaded_file having issues with WordPress - php

Trying to add a file upload to WordPress, all is working well so far except for move_uploaded_file.
<input type="file" name="attachment" id="attachment">
The field in my form above
if (!move_uploaded_file($_FILES["attachment"]["tmp_name"],WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name'])))
{
$return['error'] = true; $return['error_message'] = __('File could not be uploaded', 'btoa').'<br />';
}
Attempting to move the uploaded file, it's not working and displaying the error.
I've tried to use is_uploaded_file, which also returns false, the uploads folder is 777, the folder it is trying to save in /cv/ is also 777.
I am not quite sure what is going wrong here, there is no error log being created and I just can't seem to get it to work.
Apart from moving the uploaded file, sending out attachments is working perfectly.
Anything I can do?
FORM CODE
<form action="<?php echo home_url() ?>" method="post" id="enquiry-form" enctype="multipart/form-data">
<p><small class="error" style="margin-top: 15px; display: none;"></small></p>
<p><input type="text" value="<?php _e('Your name', 'btoa'); ?>" name="name" id="enquiry-name" onfocus="if(jQuery(this).val() == '<?php _e('Your name', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Your name', 'btoa'); ?>'); }" /></p>
<p><input type="text" value="<?php _e('Email address', 'btoa'); ?>" name="email" id="enquiry-email" onfocus="if(jQuery(this).val() == '<?php _e('Email address', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Email address', 'btoa'); ?>'); }" /></p>
<p><label for="file">Upload your CV/Resume:</label></p>
<p style="margin-bottom:0;"><input type="file" name="attachment" id="attachment"></p>
<p><textarea name="message" id="enquiry-message" cols="" rows="4" onfocus="if(jQuery(this).val() == '<?php _e('Message', 'btoa'); ?>') { jQuery(this).val(''); }" onblur="if(jQuery(this).val() == '') { jQuery(this).val('<?php _e('Message', 'btoa'); ?>'); }"><?php _e('Message', 'btoa'); ?></textarea></p>
<p><input type="submit" class="button-primary" value="<?php _e('Send', 'btoa'); ?>" /></p>
<div class="clear"></div>
<!-- /.clear/ -->
<div class="error-message"></div>
<div class="thank-you hidden">
<p><?php _e('Thank you! Your message has been successfully sent.', 'btoa'); ?></p>
</div>
</form>
SUCCESS FORM CODE
//// IF EMAIL IS VALID
if($return['error'] == '') {
/// GETS OTHER VARS
$name = isset($_POST['email']) ? trim($_POST['name']) : '';
$the_message = isset($_POST['message']) ? trim($_POST['message']) : '';
$post_id = isset($_POST['post_id']) ? trim($_POST['post_id']) : '';
//// NOW WE GET OUR SPOT AND THE USER
$spot = get_post($post_id);
$user = get_user_by('id', $spot->post_author);
//// STARTS OUR RECIPIENT ARRAY
$to = $user->user_email;
//// HEADERS
$headers = 'From: '.get_bloginfo('name').' <'.get_option('admin_email').'>'."\r\n".
'Reply-To: '.$email;
$subject = sprintf2(__('%site_name Contact: %spot_name', 'btoa'), array('site_name' => get_bloginfo('name'), 'spot_name' => $spot->post_title));
if (!move_uploaded_file($_FILES["attachment"]["tmp_name"],WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name'])))
{
$return['error'] = true; $return['error_message'] = __('File could not be uploaded', 'btoa').'<br />';
error_reporting(E_ERROR | E_WARNING | E_PARSE);
}
$attachments = array(WP_CONTENT_DIR ."/uploads/cv/".basename($_FILES['attachment']['name']));
add_filter( 'wp_mail_content_type', 'my_custom_email_content_type' );
function my_custom_email_content_type() {
return 'text/html';
}
$message = sprintf2(__("Dear %author,
%user (email: %email) has sent you a message via %site_name:
-----
%message", 'btoa'), array(
'author' => $user->display_name,
'user' => $name,
'email' => $email,
'site_name' => get_bloginfo('name'),
'attachment' => $attachments,
'message' => $the_message
));
//// SENDS OUT OUR EMAIL
if(!wp_mail($to, $subject, stripslashes($message), $headers, $attachments)) {
$return['error'] = true; $return['error_email'] = sprintf2(__('There was a problem sending your enquiry. Please email us directly at %site_email', 'btoa'), array('site_email' => get_option('admin_email')));
} else { $return['success'] = stripslashes($headers); }
}
echo json_encode($return);
exit;
}
Ignore the slightly messy code while trying to fix this bug.
Also attempted to add/adjust this in wp_config, but still no error logs being created in root or wp-content
// Enable WP_DEBUG mode
define('WP_DEBUG', true);
// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// Disable display of errors and warnings
define('WP_DEBUG_DISPLAY', false);
#ini_set('display_errors',0);
// Use dev versions of core JS and CSS files (only needed if you are modifying these core files)
define('SCRIPT_DEBUG', true);

Have you tried echoing out the WP_CONTENT_DIR and seeing what that gets? Or doing a var_dump(is_dir(WP_CONTENT_DIR .'/uploads/cv/'.basename($_FILES['attachment']['name'])). Also doing a print_r on the $_FILES array to see the actual error number it returns and correlating that with: http://us1.php.net//manual/en/features.file-upload.errors.php may help. Let me know the results to each please unless of course you figure it out.

Related

(PHP) trying to detect google recaptcha code failure

So I am almost done creating this anti spam google recaptcha v3 form.
I get failure to the end.
could you see what is the problem?
I dont use this to send data to DB but to my email.
let me know if this is the problem, but i think not.
I am almost finished, here what I have done so far:
(still getting Failed to save data. error)
<?php
if(isset($_POST['submit'])){
// print_r($_POST);
$url = "https://www.google.com/recaptcha/api/siteverify";
$data = [
'secret' => "censord",
'response' => $_POST['token'],
'remoteip' => $_SERVER['REMOTE_ADDR']
];
$options = array(
'http' => array(
'header' => "Content-type: application/
x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$res = json_decode($response, true);
if($res['success'] == true) {
//save data to database
echo '<div class="alert alert-success">
<strong>Success!</strong> Data is saved.
</div>';
} else {
echo '<div class="alert alert-warning">
<strong>warning!</strong> Failed to save data.
</div>';
}
}
?>
------------------- and the form-----------
<?php
if(isset($_POST['submit'])){
$name = htmlspecialchars(stripslashes(trim($_POST['username'])));
$email = htmlspecialchars(stripslashes(trim($_POST['email'])));
$text = htmlspecialchars(stripslashes(trim($_POST['textt'])));
if(!preg_match("/^[A-Za-z .'-]+$/", $name)){
$name_error = 'Invalid name';
}
if(!preg_match("/^[A-Za-z0-9._%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/", $email)){
$email_error = 'Invalid email';
}
if(strlen($text) === 0){
$message_error = 'Your message should not be empty';
}
if(preg_match('/http|www/i',$comments)) {
$error_message .= "We do not allow a url in the comment.<br />";
}
}
?>
<div id="container">
<div class="form-wrap">
<h1>Report bug</h1>
<p>It's free and you help us make the programming wikipedia better!</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<div class="form-group">
<label for="username">Name:</label>
<input type="text" name="username">
<p><?php if(isset($name_error)) echo $name_error; ?></p>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" name="email">
<p><?php if(isset($email_error)) echo $email_error; ?></p>
</div>
<div class="form-group">
<label for="textx">Message:</label>
<textarea type="text" name="textt" rows="22" cols="42"></textarea>
<p><?php if(isset($message_error)) echo $message_error; ?></p>
<button type="submit" name="submit" value="Submit" class="btn">Report us</button>
<?php
if(isset($_POST['submit']) && !isset($name_error) && !isset($subject_error) && !isset($email_error) && !isset($message_error)){
$to = 'censord'; // edit here
$body = " Name: $name\n E-mail: $email\n Message:\n $message";
if(mail($to, $subject, $body)){
echo '<p style="color: green">Message sent</p>';
}else{
echo '<p>Error occurred, please try again later</p>';
}
}
?>
<input type="hidden" id="token" name="token">
</form>
</div>
</div>
</body>
<script>
grecaptcha.ready(function() {
grecaptcha.execute('censord', {action: 'homepage'}).then(function(token) {
console.log(token);
document.getElementById("token").value = token;
});
});
</script>
</html>

Need Custom WordPress Form to Send All Fields in Body of Email

I have been looking for an HTML5 compliant and accessible form plugin for a site, but there is not one out there so I ended up coding one myself (from info I have found here). It works, but I want to be able to have all fields sent in the body of the email upon submission. This just sends the message from the textarea. I'm not an expert in PHP so the answer isn't obvious to me. I appreciate any help!!
<pre>
<?php
function html_form_code()
{
?>
<form action="<?php esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
<label for="url" class="hidden">URL</label>
<input type="url" name="url" id="url" class="hidden" />
<label for="cf-name">Name*</label>
<input type="text" name="cf-name" id="cf-name" placeholder="Name" pattern="[^.]*" value="<?php isset($_POST['cf-name']) ? esc_attr($_POST['cf-name']) : ''; ?>" />
<label for="cf-email">Email*</label>
<input type="email" name="cf-email" id="cf-email" placeholder="Example: name#domain.com" value="<?php isset($_POST['cf-email']) ? esc_attr($_POST['cf-email']) : ''; ?>" />
<label for="cf-phone">Phone</label>
<input type="tel" name="cf-phone" id="cf-phone" placeholder="123-456-7890" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" />
<label for="cf-message">How Can We Help You?*</label>
<textarea rows="4" name="cf-message" id="cf-message" placeholder="Your Message"><?php isset($_POST['cf-message']) ? esc_attr($_POST['cf-message']) : ''; ?></textarea>
<input type="submit" name="cf-submitted" value="SEND"/>
</form>
<?php
}
// Form validation
function my_validate_form()
{
$errors = new WP_Error();
if (isset($_POST[ 'url' ]) && $_POST[ 'url' ] !== '') {
$errors->add('cheater', 'Ignore this text box. It is used to detect spammers. If you enter anything into it, your message will not be sent.');
}
if (isset($_POST[ 'cf-name' ]) && $_POST[ 'cf-name' ] == '') {
$errors->add('name_error', 'Please tell us your name.');
}
if (isset($_POST[ 'cf-email' ]) && $_POST[ 'cf-email' ] == '') {
$errors->add('email_error', 'Please fill in a valid email.');
}
if (isset($_POST[ 'cf-message' ]) && $_POST[ 'cf-message' ] == '') {
$errors->add('message_error', 'Please send us a message.');
}
return $errors;
}
// Form delivery
function deliver_mail($args = array())
{
$defaults = array(
'name' => '',
'email' => '',
'phone' => '',
'to' => get_option('admin_email'), // can change this to an email address
);
$args = wp_parse_args($args, $defaults);
$headers = "From: {$args['name']} <{$args['email']}>"."\r\n";
$subject = "Website Inquiry";
// Send email returns true on success, false otherwise
if (wp_mail($args['to'], $subject, $args['message'], $headers)) {
return;
} else {
return false;
}
}
// Form Sanitize
function my_sanitize_field($input)
{
return trim(stripslashes(sanitize_text_field($input)));
}
// Success Message
function my_form_message()
{
global $errors;
if (is_wp_error($errors) && empty($errors->errors)) {
echo '<div class="cf-success">';
echo '<p>Thank you for contacting us '.$_POST['cf-name'].', we will be in touch with you soon.</p>';
echo '</div>';
//Empty $_POST because we already sent email
$_POST = '';
} else {
if (is_wp_error($errors) && !empty($errors->errors)) {
$error_messages = $errors->get_error_messages();
foreach ($error_messages as $k => $message) {
echo '<div class="cf-error '.$k.'">';
echo '<p>'.$message.'</p>';
echo '</div>';
}
}
}
}
// Form shortcode
add_shortcode('gr_contact_form', 'cf_shortcode');
function cf_shortcode()
{
ob_start();
my_form_message();
html_form_code();
return ob_get_clean();
}
// Error validation
add_action('init', 'my_cf_form');
function my_cf_form()
{
if (isset($_POST['cf-submitted'])) {
global $errors;
$errors = my_validate_form();
if (empty($errors->errors)) {
$args = array(
'name' => my_sanitize_field($_POST['cf-name']),
'email' => my_sanitize_field($_POST['cf-email']),
'message' => my_sanitize_field($_POST['cf-message']),
);
deliver_mail($args);
} else {
return $errors;
}
}
}
?>
</pre>

Wordpress redirect to profile page after user registration

I'm trying to redirect users after successful registration to their profile page but no matter where I put the redirect it doesn't seem to work.
The user is being registered correctly but the redirect isn't happening.
All the code seems to be functioning correctly by outputting the correct error messages when there is something that doesn't validate and also registering the user if the information is valid. The only issue is the redirect.
This is the error I am now receiving: Notice: wpdb::escape is deprecated since version 3.6.0! Use wpdb::prepare() or esc_sql() instead.
My PHP is:
<?php
$success = '';
$error = '';
global $wpdb, $PasswordHash, $current_user, $user_ID;
if(isset($_POST['task']) && $_POST['task'] == 'register' ) {
$password1 = $wpdb->escape(trim($_POST['password1']));
$password2 = $wpdb->escape(trim($_POST['password2']));
$first_name = $wpdb->escape(trim($_POST['first_name']));
$last_name = $wpdb->escape(trim($_POST['last_name']));
$email = $wpdb->escape(trim($_POST['email']));
$username = $wpdb->escape(trim($_POST['email']));
if( $email == "" || $password1 == "" || $password2 == "" || $first_name == "" || $last_name == "") {
$error = 'Please don\'t leave the required fields.';
} else if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Invalid email address.';
} else if(email_exists($email) ) {
$error = 'Email already exists.';
} else if($password1 <> $password2 ){
$error = 'Password do not match.';
} else {
$user_id = wp_insert_user( array ('first_name' => apply_filters('pre_user_first_name', $first_name), 'last_name' => apply_filters('pre_user_last_name', $last_name), 'user_pass' => apply_filters('pre_user_user_pass', $password1), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'young-person') );
if( is_wp_error($user_id) ) {
$error = 'Error on user creation.';
} else {
do_action('user_register', $user_id);
wp_redirect ( home_url("/profile") );
}
}
} ?>
And my HTML is:
<form method="post">
<div class="row">
<div class="six">
<p><label>First Name</label>
<input type="text" value="" name="first_name" id="first_name" /></p>
</div>
<div class="six">
<p><label>Last Name</label>
<input type="text" value="" name="last_name" id="last_name" /></p>
</div>
<div class="six">
<p><label>Email</label>
<input type="text" value="" name="email" id="email" required /></p>
</div>
<div class="six">
<p><label>Password</label>
<input type="password" value="" name="password1" id="password1" /></p>
</div>
<div class="six">
<p><label>Repeat password</label>
<input type="password" value="" name="password2" id="password2" /></p>
</div>
<div class="full">
<div class="alignleft"><?php if($error!= "") { echo $error; } ?></div>
<button type="submit" name="btnregister" class="button" >Submit</button>
<input type="hidden" name="task" value="register" />
</div>
</div>
</form>
Any help would be massively appreciated.
Have you disabled error reporting? I suspect you're outputting something before the redirect causing a PHP Warning: Cannot modify header information that's being suppressed (i.e. not shown), you might want to check your logs.
(Not so )long story short: check whether you're printing, echoing, etc., anything before the redirect. That will cause the redirect to fail.
Additional notes:
You may want to throw in an die('test') between the calls to do_action() and wp_direct() just to check whether this point is actually reached -- I suspect it is.
You also want to add an exit after the redirect. Check this SO question why. And also the WordPress documentation on wp_redirect():
Note: wp_redirect() does not exit automatically, and should almost
always be followed by a call to exit;.

invalid file error when using a thumbnail with link posts when posting using php SDK

I'm trying to upload a custom thumbnail with a link post using the php sdk but it is showing the error
(#100)Invalid File. Expected file of one of the following types: image/jpg, image/jpeg, image/gif, image/png
the uploaded file works ok for posting a photo so I know the file is ok, what could be the issue here when trying to post as a link?
on this page https://developers.facebook.com/docs/reference/ads-api/link_post_custom_image/
it shows it should work. I've tried ignoring the uploaded file and hard code a path to a known existing image but it still shows the error when trying to post a link with the 'thumbnail' parameter
I've tried copying the file to local first and then using that path but still it shows the error
if I leave off the thumbnail and picture parameters, facebook grabs it's own image for the thumbnail so the posting function works, just not with the thumbnail parameter
here is a sample bit of code
the html form
<form id="form" method="post" action="newpost.php" enctype="multipart/form-data">
<div id="container">
<div id="content">
<div id="fbpages">
<?php
foreach($c->accounts as $page){
echo '<li title="Post to '.$page->name.'" class="fbpage" pageid="'.$page->id.'"><img src="http://graph.facebook.com/'.$page->id.'/picture" width="37" height="37"/></li>';
}
echo '<li title="post to personal timeline" class="fbpage" pageid="personal"><img src="http://graph.facebook.com/'.$user.'/picture" width="37" height="37"/></li>';
echo '<li title="Post to Wordpress" class="fbpage" pageid="wordpress"><img src="images/wordpress-logo.png"/></li>';
?>
<input type="hidden" name="fbpages" />
</div>
<div id="fields">
<div id="text-1">
<textarea id="message" name="message"><?php if($c->alt){ echo $c->alt;}?></textarea>
</div>
<div id="image">
<img src="<?php echo $c->src;?>" />
<br><input name="nopicture" value="yes" type="checkbox"/>No Picture (let facebook choose)
<input type="file" name="file"/>
</div>
<div id="text-2">
<p>Name<br><input type="text" id="name" name="name" placeholder="name" value="<?php echo $c->title;?>"/></p>
<p>Link<br><input type="text" id="link" name="link" placeholder="link" value="<?php echo $c->foundpage;?>"/></p>
<?php $da = parse_url($c->foundpage); $caption = $da['host']; ?>
<p>Caption<br><input type="text" id="caption" name="caption" placeholder="caption" value="<?php echo $caption;?>"/></p>
<p>Description<br><textarea id="description" name="description" placeholder="description"><?php echo $c->description ? $c->description : $c->alt;?></textarea></p>
</div>
</div>
<div id="controls">
<div id="leftcontrols">
<p><strong>Auto Comment</strong><p>
<input type="checkbox" id="docomment" name="docomment" value="yes" />
<textarea id="comment" name="comment" rows="3" placeholder="Comment text"><?php echo 'Found at '.$c->foundpage;?></textarea>
</p>
</div>
<div id="rightcontrols">
<strong>Select type of post:</strong><br />
<select id="type" name="type">
<option value="photo">Post a Photo</option>
<option value="link">Post a Link</option>
<option value="status">Post a Status</option>
</select>
<p class="controls">
<strong>Time and Date to post</strong><br />
<input type="text" id="date" name="date" value="<?php echo date('d/m/Y H:i');?>" placeholder="date"/>
<br><button id="now">Now</button> <button id="plus6">+6 Hours</button>
</div>
</p>
<input type="submit" name="clear" value="clear"/>
<p id="submit">
<input type="submit" name="submit" value="Submit"/>
</p>
</div>
</div>
</div>
the function that posts as a photo that works fine
if(!empty($_FILES["file"]["tmp_name"])){
$facebook->setFileUploadSupport(true);
$c['image'] = '#'.$_FILES["file"]["tmp_name"];
}
if($type == 'photo'){
// build args
$args = array(
'message' => $message,
'published'=>$scheduledpost ? 0 : 1,
'no_story' => 0,
'access_token' => $accesstoken
);
if(isset($c['image'])){
$args['image'] = $c['image'];
} else {
$args['url'] = $c['src'];
}
if($scheduledpost){
$args['scheduled_publish_time'] = $timetopost;
}
try {
$photo = $facebook->api($pageid . '/photos', 'post', $args);
// post comment if sent
if( is_array( $photo ) && !empty( $photo['id'] ) ){
///photo posted, make comment with link
if(isset($_POST['docomment']) && $_POST['docomment'] == 'yes'){
$commentmessage = 'Found at '.$_POST['comment'];
try{
$comment = $facebook ->api('/'.$photo['id'].'/comments',
'post',
array(
'access_token' => $accesstoken,
'message' => $commentmessage,
)
);
} catch (FacebookApiException $e){
echo '<h2>Had an error updating the comment '.$e->getMessage();
}
}
}
}catch(FacebookApiException $e){
echo "<h2>Error</h2>can't post photo. It must be protected from being shared. <script>setTimeout(\"self.close();\",2500);</script>";
exit;
}
but when I try to post a link using the same uploaded file , it shows the error
if($type == 'link'){
//debugbreak();
$args = array(
'access_token' => $accesstoken,
'message' => $message,
'name' => $_REQUEST['name'],
'link' => $_REQUEST['link'],
'caption'=>$_REQUEST['caption'],
'description' => $_REQUEST['description'],
'picture'=> $c['src'],
'published'=> 1
);
if(isset($_POST['nopicture'])){
unset($args['picture']);
}
if(isset($c['image'])){
$args['thumbnail'] = $c['image'];
}
if($scheduledpost){
$args['scheduled_publish_time'] = $timetopost;
$args['published'] = 0 ;
}
try{
$link = $facebook->api('/'.$pageid.'/feed','POST',$args);
if( is_array( $link ) && !empty( $link['id'] ) ){
///photo posted, make comment with link
if(isset($_POST['docomment']) && $_POST['docomment'] == 'yes'){
$commentmessage = 'Found at '.$_POST['comment'];
try{
$comment = $facebook ->api('/'.$link['id'].'/comments',
'post',
array(
'access_token' => $accesstoken,
'message' => $commentmessage,
)
);
} catch (FacebookApiException $e){
echo '<h2>Had an error updating the comment '.$e->getMessage();
}
}
}
} catch(FacebookApiException $e){
echo "<h2>Error</h2>can't post link.<script>setTimeout(\"self.close();\",2500);</script>";
exit;
}
update
I ended up sending the image to facebook as a nostory and then get the source from the info and use that as the src for the link
if(isset($c['image'])){
$targs = array(
'published'=> 0,
'no_story' => 0,
'access_token' => $accesstoken,
'image'=>$c['image']
);
//try temporary photo
$picture = $facebook->api($pageid . '/photos', 'post', $targs);
if($picture){
// get info about picture and set src to source
$picinfo = $facebook->api($picture['id']);
$args['picture'] = $picinfo['source'];
$c['src'] = $args['picture'];
}
}

Simple PHP Contact Form: Submit Button Not Sending Emails

I am using a contact form on a site and it is not sending the email, please can anyone give me advise where this code is wrong?
This form was copied from another site that worked, so I cannot understand where it fails. I've checked the syntax and everything seems ok.
<?php
/*
Template Name: Contact Page
*/
get_header();
$contact_show = true;
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!preg_match("/^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$/i", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$contact_show = false;
$emailTo = get_option('of_email_address');
$body = "Name: $name \r\nEmail: $email \r\nSubject: $subject \r\nComments:\r\n $comments";
$headers = 'From: <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
<div id="top">
<h1><?php the_title(); ?></h1>
</div>
</div>
<div id="main_content">
<div id="contact">
<?php while ( have_posts() ) : the_post(); ?>
<?php endwhile; // end of the loop. ?>
<?php if ($contact_show == true) { ?>
<?php } ?>
<?php if(isset($hasError)) { //If errors are found ?>
<div class="redbox">
<p><?php _e('Please check if you\'ve filled all the fields with valid information. Thank you.') ?></p>
</div>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div class="greenbox">
<p>
<?php _e('Your message has been sent!') ?><br />
<?php echo $name; _e(' thank you for emailing us! We will get in touch with you soon.'); ?>
</p>
</div>
<?php } ?>
<form action="" method="post" id="contactForm"><!-- start contact form -->
<fieldset class="contact-fieldset">
<ul>
<li>
<label for="contactname"><?php _e('Name:') ?></label>
<input type="text" name="contactname" id="name" class="contact-input requiredContact" />
</li>
<li>
<label for="email"><?php _e('Email:') ?></label>
<input type="text" id="email" name="email" class="contact-input requiredContact cEmail" />
</li>
<li>
<label for="subject"><?php _e('Subject:') ?></label>
<input type="text" name="subject" id="subject" class="contact-input requiredContact" />
</li>
<li>
<label for="message"><?php _e('Message:') ?></label>
<textarea rows="6" style="overflow: hidden;" cols="40" id="message" name="message" class="contact-textarea
requiredContact"></textarea>
</li>
<li>
<input type="submit" value="<?php _e('send message'); ?>" name="submit" class="contact-submit"
/>
</li>
</ul>
</fieldset>
</form></div>
</div>
If you coppied it from another site that did work, that suggests the PHP code works and that it's in fact your server setup that is wrong as that is what you have changed (and not the PHP code, which i assume shows no errors if it was previously working). Ensure these settings are correct:
http://php.net/manual/en/mail.configuration.php
I check your coding, in that there are no errors and the reason for not working is the function calling may be.
In your coding there are several function calls are present. Check that all the functions are present and if any errors in that functions.
Again, PHP looks good; check your php.ini file and ensure that mail functions are configured to either give PHP a path to sendmail or an SMTP connection; also, be sure that your firewall settings are not blocking port 25 (or your configuration's SMTP relay port)

Categories