I am using Xampp Server to do a send a message to an email.
I am using the PHP Mailer to do this
I ran into an error and i am not sure how to fix it , I would love some assistance if you have any
`
Sending Email Using PHP
Please enter the email address
Kindly enter the subject
Kindly enter the message
Subject = $subject;
$mail -> Body = $message;
$mail -> addAddress ($to);
$mail -> AltBody = $message;
$mail -> setFrom (SEND_FROM, SEND_FROM_NAME);
$mail -> addReplyTo (REPLY_TO, REPLY_TO_NAME);
$mail -> Host = MAILHOST;
$mail -> Username = USERNAME;
$mail -> Password = PASSWORD;
$mail -> Port = 587;
$mail -> isSMTP ();
$mail -> SMTPAuth = true;
$mail -> SMTPSecure = PHPMailer:: ENCRYPTION_STARTTLS;
$mail -> IsHTML (true);
$mail -> send ();
if ($mail == true){
echo “Message sent successfully”;
}
else {
echo “Message could not be sent”;
}
}
?>
`
This is the credentials for the emails called information.php
<?php
define ('MAILHOST', "smtp.gmail.com");
define ('USERNAME', "*******@gmail.com");
define ('SEND_FROM', "*******[email protected]");
define ('SEND_FROM_NAME', "**** *****");
define ('REPLY_TO', "student email");
define ('REPLY_TO_NAME', "*******");
define ('PASSWORD', "**%^&%*");
?>
The error was
Warning: Undefined array key "to" in (file name) on line 40
Fatal error: Uncaught PHPMailerPHPMailerException: Invalid address: (to): in
1100 Stack trace: #0
: PHPMailerPHPMailerPHPMailer->addOrEnqueueAnAddress('to', NULL, '') #1(49): PHPMailerPHPMailerPHPMailer->addAddress(NULL) #2 {main} thrown in on line 1100