kemson Godwin
kemson Godwin

Reputation: 1

Uncaught phpmailer exception

I am unable to receive confirmation email because it kept showing this error message and I have try cross checking the code I don’t get the issue.

This is the error message:

Fatal error: Uncaught PHPMailer\PHPMailer\Exception: Invalid address: (to): gerald in C:\PerfLogs\htdocs\AuthSystem\vendor\phpmailer\phpmailer\src\PHPMailer.php:1094 Stack trace: #0 C:\PerfLogs\htdocs\AuthSystem\vendor\phpmailer\phpmailer\src\PHPMailer.php(1014): PHPMailer\PHPMailer\PHPMailer->addOrEnqueueAnAddress('to', 'gerald', '') #1 C:\PerfLogs\htdocs\AuthSystem\code.php(26): PHPMailer\PHPMailer\PHPMailer->addAddress('gerald') #2 C:\PerfLogs\htdocs\AuthSystem\code.php(53): sendemail_verify('gerald', 'fimmel146@gmail...', 'aa6fc4003742908...') #3 {main} thrown in C:\PerfLogs\htdocs\AuthSystem\vendor\phpmailer\phpmailer\src\PHPMailer.php on line 1094

I tried going’s through the lines stated above and this is the code on line 1094

if ($this->exceptions) { throw new Exception($error_message);

Line 1014: return $this->addOrEnqueueAnAddress('to', $address, $name);

Code.php 26 : $mail->setFrom("[email protected]", $name); $mail->addAddress($name);

Code.php 53: sendemail_verify("$name","$email","$verify_token"); echo "sent or not ?";

Upvotes: 0

Views: 510

Answers (1)

Synchro
Synchro

Reputation: 37730

This is a very straightforward issue.

  1. You have enabled exceptions in PHPMailer.
  2. You’re adding an address that’s not a valid email address (gerald)
  3. Consequently, it’s throwing an exception, but you’re not catching it

Two ways to solve this:

  1. Don’t try to use invalid addresses (validate them beforehand)
  2. Catch the exception and report the error nicely

PHPMailer provides a validateAddress method you can use (it’s the same one that’s used internally).

Upvotes: 0

Related Questions