Cant send Email over SMTP |
Hello guys, sorry in advance but i've spent the last two hours trying to send mail with Smtp gmail and it's driving me crazy.
I've tried many things but nothing worked. class Email extends BaseConfig Here is a part of my conf file: { /** * @var string */ public $fromEmail; /** * @var string */ public $fromName; /** * @var string */ public $recipients; /** * The "user agent" * * @var string */ public $userAgent = 'CodeIgniter'; /** * The mail sending protocol: mail, sendmail, smtp * * @var string */ public $protocol = 'smtp'; /** * The server path to Sendmail. * * @var string */ public $mailPath = '/usr/sbin/sendmail'; /** * SMTP Server Address * * @var string */ public $SMTPHost = 'smtp.gmail.com'; /** * SMTP Username * * @var string */ public $SMTPUser= '[email protected]'; /** * SMTP Password * * @var string */ public $SMTPPass = 'myAppPassword'; /** * SMTP Port * * @var int */ public $SMTPPort = 465; /** * SMTP Timeout (in seconds) * * @var int */ public $SMTPTimeout = 20; /** * Enable persistent SMTP connections * * @var bool */ public $SMTPKeepAlive = false; /** * SMTP Encryption. Either tls or ssl * * @var string */ public $SMTPCrypto = 'ssl'; /** * Enable word-wrap * * @var bool */ public $wordWrap = true; /** * Character count to wrap at * * @var int */ public $wrapChars = 76; /** * Type of mail, either 'text' or 'html' * * @var string */ public $mailType = 'html'; /** * Character set (utf-8, iso-8859-1, etc.) * * @var string */ public $charset = 'UTF-8'; /** * Whether to validate the email address * * @var bool */ public $validate = false; /** * Email Priority. 1 = highest. 5 = lowest. 3 = normal * * @var int */ public $priority = 3; /** * Newline character. (Use “\r\n” to comply with RFC 822) * * @var string */ public $CRLF = "\rn"; /** * Newline character. (Use “\r\n” to comply with RFC 822) * * @var string */ public $newline = "\r\n"; } Here is the controller method i'm using: class SendMail extends Controller { public function index() { return view('form_view'); } function sendMail() { $to = $this->request->getVar('mailTo'); $subject = $this->request->getVar('subject'); $message = $this->request->getVar('message'); $email = \Config\Services::email(); $email->setTo($to); $email->setFrom('[email protected]', 'Confirm Registration'); $email->setSubject($subject); $email->setMessage($message); if ($email->send()) { echo 'Email successfully sent'; } else { $data = $email->printDebugger; print_r($data); } } } And i have this error: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. I've tried my smtp credentials and i have this result: Code: Connected to smtp://smtp.googlemail.com:587/?starttls=always I know there are several culprits: Use double quotes around \r\n I have a 2 step verification in gmail so i added the app and put the password in the conf I use win 10 and laragon with php 7.4.1 My store is in dev mode and i use the last version of CI4 I'm pretty sure that the problem is easily fixable but it is driving me crazy Thanks in advance |
Messages In This Thread |
Cant send Email over SMTP - by qtd - 11-21-2021, 07:39 AM
RE: Cant send Email over SMTP - by chakycool - 11-24-2021, 07:02 AM
RE: Cant send Email over SMTP - by captain-sensible - 11-24-2021, 10:57 AM
RE: Cant send Email over SMTP - by InsiteFX - 11-25-2021, 04:24 AM
RE: Cant send Email over SMTP - by mlurie - 11-30-2021, 08:16 PM
RE: Cant send Email over SMTP - by InsiteFX - 12-01-2021, 03:12 AM
|