Tag Archives: mail

Simple mail on form submit


<?php

if(isset($_POST['Submit'])){
$to = 'ravi.loyalweb@gmail.com';
$subject = $_POST['subject'];

$name_field = $_POST['Name'];
$address_field = $_POST['Address'];
$country_field = $_POST['Country'];
$postcode_field = $_POST['Postcode'];
$telephone_field = $_POST['telephone'];
$email_field = $_POST['email'];
$size_field = $_POST['size'];
$metal_field = $_POST['Metal'];

$headers = "From: $name_field <$email_field>\r\n";
$headers .= "Reply-To: $email_field\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$body ="Name : $name_field <br/>
Address : $address_field;<br/>
Country: $country_field;<br/>
Postcode: $postcode_field;<br/>
Telephone: $telephone_field <br/>
Email: $email_field <br/>
size: $size_field <br/>
Metal: $metal_field <br/>";

mail($to, $subject, $body, $headers);
}
?>
<script language="javascript">
window.location.href = "http://www.taylortrumpets.com/thank_you.html"
</script>

Advertisements

Send email on saving post type using hook

functions.php


add_action( 'save_post', 'my_project_updated_send_emails' );
function my_project_updated_send_emails(){
if( get_post_type() == 'birs_client' ){
wp_mail('ravi.loyalweb@gmail.com','subject ok 5','message ok 5');
}
}

Add email header by theme options

functions.php


add_filter('wp_mail_from_name','custom_email_from_name');
function custom_email_from_name($emailname) {
$options = get_option( 'theme_options' );
// set a custom name for notifications
$emailname =  $options['email_title'];
return $emailname;
}

Send Email in HTML format

Support this function if you want to send mail in html format

functions.php

/* mail in html format */
add_filter(‘wp_mail_content_type’, ‘set_html_content_type’);
function set_html_content_type() {
return ‘text/html’;}

Get Admin Email address

$from_email = get_option( ‘admin_email’ ); // this function get user email from wp_options table, when user change email address so that’s not working

$blogusers = get_users( ‘role=administrator’ );
// Array of WP_User objects.
$user_email=array();
foreach ( $blogusers as $user ) {
$user_email[]=$user->user_email;
}
$from_email=implode(“,”,$user_email);

%d bloggers like this: