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.
Incoming search terms:
- integrated phpmailer with wordpress
- send wordpress email with smrtp
- sending email with wordpress php smtp
- wordpress send email
Follow us on Twitter WordPress API