My Contact Form 7 in some period of time doesn’t work in other works fine.
I am getting message:
Failed to send your message. Please try later or contact the administrator by another method
I tried to debug this and found that CF7 will call wp_mail.
It will call this code from Contact Form 7:
if ( $send ) {
return @wp_mail( $recipient, $subject, $body, $headers, $attachments );
}
But this will return false.
Hase anyone some idea what can be problem.
EDIT:
When it call wp_mail it will throw error in this part of wordpress code:
if (!$this->smtp->data($header . $body)) {
throw new phpmailerException($this->lang('data_not_accepted'), self::STOP_CRITICAL);
}
EDIT:
This data function will at the first line will call function “sendComand”:
public function data($msg_data)
{
if (!$this->sendCommand('DATA', 'DATA', 354)) {
return false;
}
.....
It will failm in this if statment.
Here is sendCommand function:
protected function sendCommand($command, $commandstring, $expect)
{
if (!$this->connected()) {
$this->error = array(
"error" => "Called $command without being connected"
);
return false;
}
$this->client_send($commandstring . self::CRLF);
$reply = $this->get_lines();
$code = substr($reply, 0, 3);
if ($this->do_debug >= 2) {
$this->edebug('SMTP -> FROM SERVER:' . $reply);
}
if (!in_array($code, (array)$expect)) {
$this->last_reply = null;
$this->error = array(
"error" => "$command command failed",
"smtp_code" => $code,
"detail" => substr($reply, 4)
);
if ($this->do_debug >= 1) {
$this->edebug(
'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $reply
);
}
return false;
}.......
and this will fail in this last if statment, this condition in if (!in_array($code, (array)$expect)) will be true.
So $expect was provided on sendCommand function call:
$this->sendCommand('DATA', 'DATA', 354)
(array)$expect) == Array([0] => 354)
and $code we will get from get_lines() function:
$reply = $this->get_lines();
$code = substr($reply, 0, 3);
When it fail in $reply is next value:
$reply = 550 5.4.5 Daily sending quota exceeded. u1sm14669850qat.27 - gsmtp
And here is get_lines() source:
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-smtp.php#L820
I’ve had this issue before and resolved it by switching to gmail’s smtp by using this plugin:
https://wordpress.org/plugins/wp-mail-smtp/faq/
All you need to set it up is a gmail account, if this is a client/work website, you can create a free account with gmail and simply enter it in the plugin settings.