Many people want to sent the email through smtp from wordpress. WordPress uses the PHPmailer in there CMS. But many wordpress developer dont know how to use the wordpress phpmailer functionality. Using PHPmailer you can send the email using STMP service.

Many people use the wordpress plugins for sending the email. But I recommend not to use any wordpress plugin code for this. Because many of wordpress plugin code are not necessary and that will not useful for your wordpress application.
Here in this article I will show you how to sent email using wordpress with SMTP settings.
Use the following code for this:
// SMTP email sent
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'Username';
$phpmailer->Password = 'password';
$phpmailer->IsSMTP(); // telling the class to use SMTP
$phpmailer->Host = "hostname.com"; // SMTP server
$phpmailer->FromName = $_POST[your_email];
$phpmailer->Subject = $_POST[your_subject];
$phpmailer->Body = $_POST[your_message]; //HTML Body
$phpmailer->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$phpmailer->WordWrap = 50; // set word wrap
$phpmailer->MsgHTML($_POST[your_message]);
$phpmailer->AddAddress('support@wordpressapi.com/files/', 'Wordpress support');
//$phpmailer->AddAttachment("images/phpmailer.gif"); // attachment
if(!$phpmailer->Send()) {
echo "Mailer Error: " . $phpmailer->ErrorInfo;
} else {
echo "Message sent!";
}
Use the above code for sending the email from wordpress. With godaddy hosting service above code is very useful for creating the contact us page.
If you are having any issues or question about using the code then please write to me.






You didn’t say how you’re sending the $_POST[your_message] variable. Could you give an example of that? Say you want to email a post you just wrote to someone. How would you go about sending the text of that post through the phpmailer you’re showing?
I did not get your question exactly. Can you tell me what you want to do with the script.
Excellent stuff! I have to agreed with what you may have written, as well as the info that you just have provided will help a good deal of men and women available too. Maintain the excellent high quality work.
sometimes,blogging is very tired.However,I can get much happiness from it.
hi
thanks for the tutorial. one question though … what would be the username and password. is it email username and password or domain username and password or wp admin username and password or what?
For sending email dont use the wp admin username and password. You need get that from your hosting provider. (ask them for give smtp details for email address of your domain)
This post makes a lot of sense !
I would like to say “wow” what a inspiring post. This is really great. Keep doing what you’re doing!!
Hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.
Thanks for posting. Good to see that not everyone is using RSS feeds to build their blogs
I REALLY liked your post and blog! It took me a minute bit to find your site…but I bookmarked it. Would you mind if I posted a link back to your post?
Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…
Where do I insert the code?
I was just having a conversation over this I am glad I came across this it cleared some of the questions I had.
Good! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?
Intriguing post. I have been searching for some good resources for solar panels and discovered your blog. Planning to bookmark this one!
Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…
I’ve been checking your blog for a while now, seems like everyday I learn something new
Thanks
I REALLY liked your post and blog! It took me a minute bit to find your site…but I bookmarked it. Would you mind if I posted a link back to your post?
Awesome post. I so good to see someone taking the time to share this information
Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader
Good! Thank you! I always wanted to write in my site something like that. Can I take part of your post to my blog?
Hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.
Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader
I’ve just started off a blog, the knowledge you give on this site has aided me extremely. Thank you for all your time & work.