Created
April 4, 2017 04:32
-
-
Save tradesouthwest/c91a2b5c183b84a532b9484ee95af2df to your computer and use it in GitHub Desktop.
wp send mail function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Uses wp_mail() to send out email address | |
* from a single field form. | |
* Here is the form: | |
************************************************************************************ | |
<form id="newsletterForm" action="<?php the_permalink(); ?>" method="POST"> | |
<div class="input-group"> | |
<input class="form-control" | |
placeholder="Email Address" | |
name="email" id="newsEmail" type="email" | |
value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>"> | |
<span class="input-group-btn"> | |
<button class="btn btn-default" | |
type="submit"><?php _e( 'Send', 'valuadd' ); ?></button> | |
</span> | |
<input type="hidden" name="submitted" id="submitted" value="true" /> | |
</div> | |
</form> | |
*************************************************************************************** | |
* @usage: send_valuadd_news_form(); put just above form ON SAME PAGE as form | |
* | |
*/ | |
function send_valuadd_news_form(){ | |
if (!isset($_POST['submitted'])) { return; } | |
// get the info from the from the form | |
$form = array(); | |
$form['email'] = $_POST['email']; | |
// Build the message | |
$message = "Email : " . $form['email'] ."\n"; | |
//set the form headers | |
$headers = get_option('blogname'); | |
// The email subject | |
$subject = __( 'Newsletter Sign Up', 'valuadd' ); | |
// Who are we going to send this form too | |
$send_to = get_option('admin_email'); | |
$sentSuccess = wp_mail( $send_to, $subject, $message, $headers ); | |
if ( $sentSuccess ) | |
{ | |
$messageGood = __( 'We are so glad you can become part of our Website. We will be sending you our response as soon a we can.', 'valuadd' ); | |
echo '<div class="alert alert-success" id="newsletterSuccess">'; | |
echo $messageGood; | |
echo '</div>'; | |
} else { | |
echo $messageBad = __( 'Would you please use our contact form. There seems to be trouble with sending this form.', 'valuadd' ); | |
echo '<div class="alert alert-danger" id="newsletterSuccess">'; | |
echo $messageBad; | |
echo '</div>'; | |
} | |
} | |
add_action('after_body', 'send_valuadd_news_form'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment