Reputation:
I am new in wordpress. I am sending mail via wp-mail function locally I have install east wp-mail plugin for smtp.
include("wp-mail.php");
$to = '[email protected]';
$subject = 'Apple Computer';
$message = 'Steve, I think this computer thing might really take off.';
wp_mail( $to, $subject, $message );
But I am getting error liike :
Slow down cowboy, no need to check for new mails so often!
Please guide me....
Do i need to change in any file or install any plugin ???
Upvotes: 1
Views: 4259
Reputation: 664
If you not want to use any plugin to setup your smtp you can do it easy with code . WordPress have their own hook to setup smtp.
Here is the code. Simply by adding your Host, Username and Password. You can send email from your local machine.
add_action( 'phpmailer_init', 'my_phpmailer_example' );
function my_phpmailer_example( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.example.com';
$phpmailer->SMTPAuth = true; // Force it to use Username and Password to authenticate
$phpmailer->Port = 25;
$phpmailer->Username = 'yourusername';
$phpmailer->Password = 'yourpassword';
// Additional settings…
//$phpmailer->SMTPSecure = "tls"; // Choose SSL or TLS, if necessary for your server
//$phpmailer->From = "[email protected]";
//$phpmailer->FromName = "Your Name";
}
You can learn more about it on WordPress Codex
Upvotes: 1
Reputation: 874
wp_mail
works similar to PHP's function mail
. You can read more about it here. PHP mail
function needs access to sendmail
binary, as stated in docs, you shouldn't have this configured in localhost, that's why it fails to send emails.
In order to send emails when testing your site in localhost you should configure SMTP to send emails.
There's a pretty good plugin called WP Mail SMTP, you can install it here.
It overrides the wp_mail
function and enables you to send emails using the Gmail SMTP server, for instance. You can use any SMTP server you want.
Upvotes: 3