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 = 'test#gmail.com';
$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 ???
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.
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 = "you#yourdomail.com";
//$phpmailer->FromName = "Your Name";
}
You can learn more about it on WordPress Codex
Related
I'm setting up an email configuration with PHPMailer and just work fine with local email in my office, but since I want use Sendinblue as an email API I just stucked and it didn't work.
I tried to find some suggest to fixed it but stucked. Did anyone try to figure out what I'm looking for about Sendinblue with PHPMailer?
With PHPMailer Library in background, I usually use this code to run my program
function send_mail2($from,$from_name,$to,$to_name,$cc,$cc_name,$cc2,$cc_name2,$cc3,$cc_name3,$subjek,$template,$is_smtp,$usermail,$password){
$sendmail = new PHPMailer();
if($is_smtp = 'Y'){
$sendmail->IsSMTP(); // enable SMTP
// $sendmail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$sendmail->SMTPAuth = true; // authentication enabled
$sendmail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$sendmail->Host = "192.x.x.x";
$sendmail->Port = 465; // or 587
$sendmail->Username = "xxx#xxx.com";
$sendmail->Password = "xxx";
}
$sendmail->setFrom("xxx#xxx.com","xxx#xxx.com"); //email pengirim
$sendmail->addReplyTo("xxx#xxx.com","xxx#xxx.com"); //email replay
$sendmail->addAddress($to,$to_name);
$sendmail->AddCC($cc,$cc_name);
$sendmail->AddCC($cc2,$cc_name2);
$sendmail->AddCC($cc3,$cc_name3);
$sendmail->Subject = $subjek;
$sendmail->Body=$template;
$sendmail->isHTML(true);
if(!$sendmail->Send()) {
return "failed";
}else{
return "success";
}
}
I just want to find how to use Sendinblue with PHPMailer.
First of all, it looks like you're using an old version of PHPMailer and have based your code on a very old example, so upgrade.
It doesn't look like you're even trying to use sendinblue; you're pointing your script at a local mail server. Because you're using a literal IP address, SSL will never work because it will fail to verify the certificate.
If you want to use sendinblue directly from PHPMailer, you need to use sendinblue's SMTP servers, and that will be covered in their documentation. If they don't provide an SMTP service (like say mailgun does), you will need to use their HTTP API instead (which has plenty of documentation). You can't use PHPMailer for talking to that, though you can use it for generating messages to send, for example by doing everything as you currently are except don't call send(); do this instead:
$message = $sendmail->getSentMIMEMEssage();
This will give you a fully-formatted RFC822 message ready to submit to an HTTP API.
When you need to configure sendinblue with PHPMailer,
At that time, first, get all configuration detail from your sendinblue account
like Host, Username, Password
And then your PHPMailer use getSentMIMEMEssage(); instend of $mail->isSMTP() or $mail->isMail()
Please check the below screenshot for reference.
I'm using godaddy for hosting my site and using default godaddy mail service.
Now i want to sent email using php mail function to other email address from my 1 of my 15 email address of my godaddy's email accounts
How can i fix that from which email address email will be sent and how to place the username and password for the email address ?
Thanks
The PHP mail function uses the mailserver configured for that webhost. You can't change that. Since godaddy controls the mailserver they control what headers it sends. You could try inserting a custom From header but I doubt that will work. It will either get modified, flagged as spam, or rejected.
If you have 15 accounts at godaddy, perhaps it's time to look for a more serious hosting solution?
Instead of using the mail() function, which just calls the OS mail function (i.e. sendmail), try something like SwiftMail (free PHP mail library). It support many different ways of sending mail, including logging into a mail account and sending email, just like you would do from your own computer. You could even send email from a gmail account if you wanted.
http://swiftmailer.org/
I am using godaddy hosting . Just keep some fields blank and send mail it will work .
please see below code its working for me.
<?php
include("class.phpmailer.php");
function sendMail($address,$username,$body){
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// $mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $mail->Host = "smtp.gmail.com"; // sets as the SMTP server
// $mail->Port = 465; // set the SMTP port for the server
// $mail->Username = "xyz#gmail.com"; // username
// $mail->Password = "test121232"; // password
$mail->SetFrom('contact#example.co.in', 'Contact');
$mail->Subject = "Enquiry for tour and travels package";
$mail->MsgHTML($body);
$address = $address;
$mail->AddAddress($address, $username);
$mail->AddCC('contact#example.co.in');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
?>
just changed from email address, so you can send mail through this email id.
$mail->SetFrom('youremail#example.co.in', 'Contact');
I've had this issue on a couple of client accounts.
After MUCH playing around, I found that it didn't matter what email app or code you use.
I finally compared two accounts. One where I know email sends from PHP, and one where it doesn't. The difference I found was:
Working account had these 2 dns entries on the domain:
CNAME / mail / #
MX / # / mail.yourdomainname.com
And the MX Entry set within CPanel Zone Editor of:
Destination: yourdomainname.com
The account that was NOT working was the same, except it did not have the CNAME entry mentioned above. I added it, waited a few minutes and tested my code again and I finally started receiving the emails from my code!
This one worked for me.
I asked Godaddy and support they told me to use relays. So Instead of using mail() function, I used PHPMailer. Kindly check below the configuration for PHP Mailer.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->setFrom('from#mail.com', 'From Mail');
$mail->addAddress('to#mail.com', 'To Mail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body 123");
$mail->AltBody = 'HTML messaging not supported';
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
Note: Here from#mail.com is my mail ID which is in cPanel mail accounts.
I have written a class in PHP which I use for sending mails making use of a Gmail account. This class in turn uses the PHPMailer library. The setup is WAMP 2.4 on Windows Vista. Using the microtime() function in PHP, I see that it takes anywhere between 5 to 6 seconds to send a single mail. Is it normal for a PHP script running on the kind of set up that I have to take as much as 5-6 seconds for a single mail going out. Here is code for the class.
<?php
require_once("phpmailer/class.phpmailer.php");
require_once("phpmailer/class.smtp.php");
class Mailer {
// Needs to be set per object
public $subject;
public $message;
public $to_name;
public $to;
private $mail; // This is the main mail object that'll be initialized
public function __construct() {
// Need to create a PHPMailer object in the constuctor and return it for use in this class.
$mail = new PHPMailer();
$from_name = "bleh";
$from = "bleh#gmail.com";
$username = "bleh";
$password = "bleh";
$mail->FromName = $from_name;
$mail->From = $from;
$mail->Username = $username;
$mail->Password = $password;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
// $mail->Port = 587; // Turns out, I dont need this one.
$mail->SMTPAuth = true; // gmail requires this
$mail->SMTPSecure = 'tls'; // gmail requires this
$this->mail = $mail;
}
function send() {
$mail = $this->mail; // The mail object
$mail->Subject = $this->subject;
$mail->Body = $this->message;
$mail->AddAddress($this->to, $this->to_name);
$result = $mail->Send();
return $result;
}
}
?>
Code used to test this -
$startTime = microtime(true);
require_once("mailer.php");
$mailer = new Mailer();
$mailer->subject = "Test";
$mailer->message = "Test";
$mailer->to_name = "My Name";
$mailer->to = "anemail#address";
$mailer->send();
echo "Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";
It is very common for SMTP to take a long time - it's even used as an anti-spam measure in the form of greetdelay/tarpit mechanisms. RFC2821 section 4.5.3.2 allows up to a 5 minute delay before traffic starts. SMTP is not intended for interactive use (since it can't queue in that situation), and sending via SMTP during web page submission can suffer because of that. Sendmail or SMTP via an async process would avoid the issue.
In PHPMailer you can enable SMTP debug output and it will show you what's happening so you'll be able to see what's taking the time:
$mail->SMTPDebug = 2;
As mentioned in my comment, Gmail may be rate limiting you. There could also be some aspect of your network communication with Gmail that is causing the issue.
You can manually begin an SMTP conversation with Gmail from the command line. Watch for how long each step takes, and check for any codes / messages that may come back from Gmail indicating a problem.
For details on how to create a manual SMTP conversation see
Connecting to smtp.gmail.com via command line
Messages that come back will be Base64 encoded as indicated in that answer. You can use an online Base64 decoder to convert back to plain text.
Note: The link shows instructions for Linux. If you don't have a Linux server to test from, you can use Cygwin (for windows) or an OpenSSH for Windows package that does not require a full Cygwin install
I have faced to same problem and its getting around 30s to send the email.
The problem was system running PHP server got hang until the email is sent.
I tried many solutions but easiest way was start another PHP server locally on different port for handle the mail sending.
The main PHP server (system running server) will handed over the mail sending request to the mail PHP server and continue no the process.
Still 30s will take to send the email, but not effect to the main PHP server.
if(mysql_affected_rows()==1)
{
$msg="To activate your account, please click on the following link:\n\n
http://localhost:80/activate.php?email=".urlencode($email)."&key=".$activation;
if(mail($email,"Registration Confirmation", $msg, "From: myemail#mycompany.com\r\nX-
Mailer: php"))
{
echo '<div> Thank you for registering. A confirmation email has been sent to '.
$email.'.Please click on the link to activate your account then</div>';
}
}
I use that code snippet to send an email from myemail#mycomapany.com to $email (myyahoo#yahoo.com) but I fail to receive any email in the yahoo account. I have got the echoed message displayed in the browser to indicate the successful mailing, though. Also, I have tried sending an email from myemail#mycomapany.com to the yahoo account directly via Outlook and it works fine. Would someone please help me fix that source snip or any kind of extra settings to make the mail function work ? Thank you so much.
EDIT: By the way, I also set up my php.ini's stmp script block as follows,
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.mycompany.com
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster#localhost
My problem is to set my local computer as a local mail server, and i editted php.ini as above but it still doesn't work.
[RESOLVED]
<?php
function SendMail($from, $to, $subject, $body)
{
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.mycompany.com";
$mail->SMTPAuth = true;
$mail->Username = "My name"; // SMTP username
$mail->Password = "mypassword"; // SMTP password = one used in Outlook
$mail->From = "myemail#mycompany.com";
$mail->FromName = "Registration Confirmation Email";
$mail->AddAddress($to);
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
return false;
}
return true;
}
?>
I include the above code snip to demonstrate a small but working example that uses phpmailer. Thanks to the one who introduces it to me in the post below.
Take a look at phpMailer it's good and very easy to use, and you can send email-s from your existing email accounts (like gmail)
Try this one, from this script you can also send email from your local file to external email.
require_once('class.phpmailer.php');
define('SMTPSERVER', 'mail.yourcompany.com');// sec. smtp server
define('SMTPUSER', 'info#yourcompanyname.com'); // sec. smtp username
define('SMTPPWD', '123456'); // sec. password
$useremail = 'mail#mail.com';
$msg = 'your text here';
$from = 'info#yourcompanyname.com';
$mailTest=new EmailService();
if ($mailTest->generalMailer($useremail, $from, 'Yoursite.com', 'Your company name', $msg)) {
} else {
if (!$mailTest->generalMailer($useremail, $from, 'Yoursite.com', 'Your company name', $msg)) {
if (!empty($error)) echo $error;
} else {
echo 'Yep, the message is send (after hard working)';
}
}
header("location:index.php?email_msg=Email sent successfully");
You should look into mail headers. Most of the time the reason is either:
Skipped Reply to/From headers
Skipped X-Mailer
For further details, please see here.
Edit
Ok, I think I know where the problem might be.
There is quite a big difference between LAMP and WAMP. Linux systems tend to have the sendmail library, which allows you to send mail to other systems without configuring anything. Windows does not.
Therefore, you should have an SMTP server installed, in order to send mail to outer sources. Take a look at this question for details.
Also, if you have a need to test this, you should take a look at Papercut, which is indispensable while testing your system.
If you can send a plain mail(), you should be able to send a mail from a library too. Not the opposite way around. Only exception is, if you use an already existing SMTP/IMAP server to do this, e.g. Gmail.
Are you sure that you have an MTA (Mail Transport Agent = Mailserver) installed on your local machine? Otherwise, you'll need to use your ISP's SMTP server instead.
Mostly that will be mail.yourprovider.com or smtp.yourprovider.com (the same hostname as what you use for outgoing mail in Outlook). PHP cannot mail by itself, it needs an MTA (either locally or remote) to do so.
I'm using godaddy for hosting my site and using default godaddy mail service.
Now i want to sent email using php mail function to other email address from my 1 of my 15 email address of my godaddy's email accounts
How can i fix that from which email address email will be sent and how to place the username and password for the email address ?
Thanks
The PHP mail function uses the mailserver configured for that webhost. You can't change that. Since godaddy controls the mailserver they control what headers it sends. You could try inserting a custom From header but I doubt that will work. It will either get modified, flagged as spam, or rejected.
If you have 15 accounts at godaddy, perhaps it's time to look for a more serious hosting solution?
Instead of using the mail() function, which just calls the OS mail function (i.e. sendmail), try something like SwiftMail (free PHP mail library). It support many different ways of sending mail, including logging into a mail account and sending email, just like you would do from your own computer. You could even send email from a gmail account if you wanted.
http://swiftmailer.org/
I am using godaddy hosting . Just keep some fields blank and send mail it will work .
please see below code its working for me.
<?php
include("class.phpmailer.php");
function sendMail($address,$username,$body){
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
// $mail->SMTPAuth = true; // enable SMTP authentication
// $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
// $mail->Host = "smtp.gmail.com"; // sets as the SMTP server
// $mail->Port = 465; // set the SMTP port for the server
// $mail->Username = "xyz#gmail.com"; // username
// $mail->Password = "test121232"; // password
$mail->SetFrom('contact#example.co.in', 'Contact');
$mail->Subject = "Enquiry for tour and travels package";
$mail->MsgHTML($body);
$address = $address;
$mail->AddAddress($address, $username);
$mail->AddCC('contact#example.co.in');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
?>
just changed from email address, so you can send mail through this email id.
$mail->SetFrom('youremail#example.co.in', 'Contact');
I've had this issue on a couple of client accounts.
After MUCH playing around, I found that it didn't matter what email app or code you use.
I finally compared two accounts. One where I know email sends from PHP, and one where it doesn't. The difference I found was:
Working account had these 2 dns entries on the domain:
CNAME / mail / #
MX / # / mail.yourdomainname.com
And the MX Entry set within CPanel Zone Editor of:
Destination: yourdomainname.com
The account that was NOT working was the same, except it did not have the CNAME entry mentioned above. I added it, waited a few minutes and tested my code again and I finally started receiving the emails from my code!
This one worked for me.
I asked Godaddy and support they told me to use relays. So Instead of using mail() function, I used PHPMailer. Kindly check below the configuration for PHP Mailer.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = "relay-hosting.secureserver.net";
$mail->Port = 25;
$mail->setFrom('from#mail.com', 'From Mail');
$mail->addAddress('to#mail.com', 'To Mail');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML("test body 123");
$mail->AltBody = 'HTML messaging not supported';
if(!$mail->send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "Message sent!";
}
Note: Here from#mail.com is my mail ID which is in cPanel mail accounts.