Wordpress smtp mail from address is not working - wordpress

i am using wp_mail_smtp for sending mail in WordPress and its working fine expect one thing i have define the from email : abc#mysite.com and from name: my site and username password for smtp authentication is : someemail#example.com and password of my mail id.
now problem is that when i sending the mail than i receive mail header like
mysite< someemail#example.com > and it should be mysite< abc#mysite.com > i have also set the filter for from name and from mail like below code
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return 'abc#mysite.com';
}
function new_mail_from_name($old) {
return 'mysite.com';
}
and my mail code is
$headers = 'From: abc#mysite.com ' . "\r\n";
$to = "admin#test.com"
$send_subject = "Mail Subject"
$message .= "Some message";
wp_mail( $to, $send_subject, $message,$headers );
please tell me what i am doing wrong so that i can receive mail header correctly
Thanks

Related

WordPress notifications not received in G-mail with altered header information

I have customized the default welcome e-mail send out by WordPress when you add a user, but when I change the default "From" information it no longer gets delivered to #gmail.com e-mailaddresses. I have tried it with multiple accounts, but always the same results. I haven't had any problems with #hotmail.com or any custom domain e-mailaddresses.
Below is the function I used to alter the default e-mail:
// Change the default welcome e-mail
add_filter( 'wp_new_user_notification_email', 'welcome__email', 10, 3 );
function welcome__email( $wp_new_user_notification_email, $user, $blogname ) {
$wp_new_user_notification_email['subject'] = sprintf(__( 'Company Name | Complete registration' ), $blogname, $user->user_login );
// Set password link
$key = get_password_reset_key( $user );
// Build the email
$message = sprintf(__('Welcome!')) . "\r\n\r\n";
$message .= 'By clicking the link below you can activate your account:' . "\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";
$message .= "After setting a password you can login." . "\r\n";
$wp_new_user_notification_email['message'] = $message;
// Change header information
$wp_new_user_notification_email['headers'] = 'From: Company Name <noreply#example.com>';
return $wp_new_user_notification_email;
}
If I comment out the last part about the 'headers' the e-mail with link to set a password does get delivered to #gmail.com e-mailaddresses, but ofcourse the default name and e-mailaddress are show then.
I can't see what I am missing out here to make sure the e-mails get delivered to #gmail.com addresses, so I'm hoping anybody here is able to help me in the right direction.
PS: I do not have any SMPT plug-in set-up.
I just noticed the e-mails are not send to #gmail.com addresses because the sender e-mailaddress does not belong to the same domain as where the website is on. Once these match, there no longer is an issue.

Contact form 7 email using SMTP

I created a web site using WordPress.
I added Contact Form 7 in my side bar.
After I filled the fields in the contact form, and click the Send button, I got an error message in a red box:
There was an error trying to send your message. Please try again
later.
I did not install phpmailer. I wrote a test php (testemail.php showed below). When I visit http://www.MyDomainName.com.au/testemail.php in the browser, it shows whole codes of the testemail.php!
Do I have to install a phpmailer plugin, for example, Easy WP SMTP?
What is the problem in testemail?
Finally how to make my contact form working?
The testemail.php code:
function sendMail($request) {
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = mail#MyDomainName.com.au;
$mail->SMTPAuth = true;
$mail->Username = 'mail#MyDomainName.com.au';
$mail->Password = 'myPassword';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('mail#MyDomainName.com.au', 'Title');
$mail->addAddress(xxx#hotmail.com);
$mail->addReplyTo('mail#MyDomainName.com.au');
$mail->isHTML(true);
$mail->Subject = '$Something';
$mail->Body = 'The body of the email';
$mail->AltBody = 'Alternative'; // this is mostly sent to your own mail
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}

PHPMailer & WordPress "Post by Email" - not creating post

I'm creating a script for a client using their PHP 5.4.16 (updating is not in the scope of this project), and therefore PHPMailer 5.2.25. My script (below) works if I change the SetAddress to my personal Gmail account (I get the email with subject, body, and attachment (the latter being the reason for using PHPMailer)), but if I change the SetAddress to my WordPress "Post by Email" address, nothing seems to be delivered.
Questions:
Is there anything wrong with my script? Missing headers? Badly formatted email?
If my script is apparently OK, what other avenues of investigation might there be?
Thanks
<?php
echo "<p>" . date("h:i:sa");
?>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/../www/phpmailer/class.phpmailer.php'); ?>
<?php require_once($_SERVER['DOCUMENT_ROOT'] . '/../www/phpmailer/class.smtp.php'); ?>
<?php
$mail = new PHPMailer();
$mail->IsSMTP(); // enable SMTP
//$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 587; // or 587
$mail->IsHTML(true);
$mail->Username = "my#gmail.com";
$mail->Password = "mypassword";
$mail->From = "my#gmail.com";
$mail->FromName = "Me";
//$mail->AddAddress("caju317davu#post.wordpress.com");
$mail->AddAddress("my#gmail.com");
$mail->AddReplyTo("my#gmail.com","developer");
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT'] . '/../www/_assets/articles/223/610/7f10120230e612e03eea9aa54a48a68f.jpg', 'attachment.jpg');
$mail->Subject = "My test email";
$mail->Body = "Hi! This is my first successful post created through email.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
Now I am not sure if this will help at all but below is the code that I have for a working version of PHPMailer v5.2.9 that is running on a site using PHP version 5.4.16 so may help. The obvious differences I can see is the recipient's section don't have "set" or "Add" and also I can't seem to find the initiator ($mail->send();). Let me know if this helps and for any areas needing extra clarification.
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.host.co.uk'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mail#example.co.uk'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('email#example.co.uk', 'Company Name');
$mail->addAddress($email); //Gets the email the enquiry form field contains
$mail->addReplyTo('email#example.co.uk', 'Company Name');
$body='<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica,
sans-serif; font-size:12px; margin:0; padding:0;">
<p>Thank you for your enquiry, a member of the team will be in touch shortly to discuss your requirements. In the mean time, please double check the below details entered on our website. If any of these are incorrect or you wish to add to it, please contact us via email or over the phone.</p></div>';
//Content
$mail->isHTML(true);
$mail->Subject = $subject ;
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
$mail->send();
echo $thankyou_text;
} catch (Exception $e) {
echo $failed_text;
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
From a 'Happiness Engineer' at WordPress:
Hi there!
At WordPress.com we don't allow posts to be sent automatically from
scripts such as PHPMailer.
I guess that answers that! Now to forget PHPMailer, and try and get back to default PHP mail() :(
Sorry to have bothered you all

Buddypress - activation link not sent to user's email address

I recently installed buddypress in my wordpress.
When a person registers on my website using registration form
a message appears saying that an activation link has been sent to the email address you provided, but user receives no email.
Please tell me to solve this.
is there any problem in wp_mail or do I need to config
something in my hosting file manager?
First , test the wp_mail function with the following code by creating wp-test.php in root folder.
include 'wp-load.php';
$to = 'example#example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
After that if it's still not working , you need to install and configure Easy WP SMTP and setup the SMTP settings from your host.

Wordpress Php auto email to comment author

I'd love to be able to automatically send a response to the person who comments on a post on my site. Their email is required so I feel as though I should be able to grab that and use php to send an email back to that email address...
I know the basics for a php email go as follows... So I just need help grabbing the authors email and putting it into the mailTo variable
<?php
$subject = 'My subject';
$message = "The Message I'd like to send back to the commenter";
$mailTo = get_comment_author_email_link
mail($mailTo, $subject, $message);
?>
Thanks!
I think what you need is to hook to the comment post action with your defined own function as such:
<?php
function sendMail($id){
$subject = 'My subject';
$message = "The Message I'd like to send back to the commenter";
$comment=get_comment($id);
$mailTo = $comment->comment_author_email ;
mail($mailTo, $subject, $message);
}
add_action('comment_post', 'sendMail');
?>
you can use this , but dont forget the comment of webarto :
http://wordpress.org/extend/plugins/wp-comment-auto-responder/

Resources