Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ composer require snipworks/php-smtp
use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 25);
$mail->setLogin('sender@example.com', 'password');
$mail->setLogin('sender@example.com', 'password', false); // set 3rd parameter to true to use PLAIN auth instead of LOGIN auth
$mail->addTo('recipient@example.com', 'Example Receiver');
$mail->setFrom('example@example.com', 'Example Sender');
$mail->setSubject('Example subject');
Expand All @@ -38,7 +38,7 @@ use Snipworks\Smtp\Email;

$mail = new Email('smtp.example.com', 587);
$mail->setProtocol(Email::TLS);
$mail->setLogin('sender@example.com', 'password');
$mail->setLogin('sender@example.com', 'password', false); // set 3rd parameter to true to use PLAIN auth instead of LOGIN auth
$mail->addTo('recipient@example.com', 'Example Receiver');
$mail->setFrom('example@example.com', 'Example Sender');
$mail->setSubject('Example subject');
Expand Down Expand Up @@ -67,7 +67,7 @@ define('SMTP_PRIMARY_PASSWORD', 'my very secret password');

require_once('config.php');
// ...
$mail->setLogin(SMTP_PRIMARY_EMAIL, SMTP_PRIMARY_PASSWORD);
$mail->setLogin(SMTP_PRIMARY_EMAIL, SMTP_PRIMARY_PASSWORD, false);
// ...
```

Expand Down
18 changes: 14 additions & 4 deletions src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Email
/** @var string $password */
protected $password;

/** @var bool $plain_auth */
protected $plain_auth;

/** @var int $connectionTimeout */
protected $connectionTimeout;

Expand Down Expand Up @@ -195,10 +198,11 @@ public function addAttachment($attachment)
* @param string $password
* @return Email
*/
public function setLogin($username, $password)
public function setLogin($username, $password, $plain_auth = false)
{
$this->username = $username;
$this->password = $password;
$this->plain_auth = $plain_auth;

return $this;
}
Expand Down Expand Up @@ -327,9 +331,15 @@ public function send()
$this->logs['HELLO'][2] = $this->sendCommand('EHLO ' . $this->hostname);
}

$this->logs['AUTH'] = $this->sendCommand('AUTH LOGIN');
$this->logs['USERNAME'] = $this->sendCommand(base64_encode($this->username));
$this->logs['PASSWORD'] = $this->sendCommand(base64_encode($this->password));
if ($this->plain_auth) {
$this->logs['AUTH'] = $this->sendCommand('AUTH PLAIN');
$this->logs['AUTH_PLAIN'] = $this->sendCommand(base64_encode( "\0". $this->username ."\0". $this->password ));
} else {
$this->logs['AUTH'] = $this->sendCommand('AUTH LOGIN');
$this->logs['USERNAME'] = $this->sendCommand(base64_encode($this->username));
$this->logs['PASSWORD'] = $this->sendCommand(base64_encode($this->password));
}

$this->logs['MAIL_FROM'] = $this->sendCommand('MAIL FROM: <' . $this->from[0] . '>');

$recipients = array_merge($this->to, $this->cc, $this->bcc);
Expand Down